detecting checkmate

Posted on 2006-05-21
Last Modified: 2013-12-26
How do I programmatically detect checkmate in chess? I can't think of any shortcuts. To detect it I would just have to:
  1. see if there's a way to capture the piece that has the king in check
  2. for non-knight pieces, look at every square along the path of check and see if it's possible to move a piece into that path without opening a path that results in check again.
  3. see if there are any open spaces around the king which are not currently in check.

If I have to do it that way, am I missing anything?
Question by:HappyEngineer
    LVL 84

    Accepted Solution

    Those are the only way of getting out of check.
    You cannot castle out of check.
    LVL 62

    Expert Comment

    by:☠ MASQ ☠
    1. Look for pins. Will removing the threatening piece open up another check?

    2. What about knight pieces? Currently you are not looking at blocking the check with a knight.

    Assuming check, then programatically you need to look at each permutation that removes check then test:
    - is the move illegal?
    - does the move result in a further check before the opponent's move?

    If all permutations are tried and any one move scores 'no' to both these tests then it is not checkmate
    LVL 9

    Expert Comment

    by:Derek Jensen
    You want to make sure all the rules are set up correctly first. That way it will make it slightly easier when testing for checkmate to check all the rules first. That will cut down significantly on the number of checks you have to run on the king itself. Or you can set up unique rules associated with each piece, that way you don't have to check against checkmate every move, only when the king is threatened.
    LVL 10

    Expert Comment


    (download  PDF )install adope acrobat reader from adope site if u dont have it runs pdf.... -

     i can give u more but this is not likely i think u may like.........I recommend lots and lots of playing chess and reading books on it.....also Make sure u make the right opening move ( The best  i think is to play the pawn infront of the king so then u can move both of ur queen and knight )  ..........This site is gr8 to play chess online (install java ) cause u can easily get opponets from beginers to g8 Experts..........and its free.....just make a free account on it with good players and u will learn how to avoid check mates ....Links above will help ....

    lastly google up with keywords such as   "avoid checkmate chess" ,"how play chess"...

    kisses to u
    best of luck
    LVL 10

    Expert Comment

    There might be a link of helping in the game........or give trick buttons ......but make sure u can loose too.....i recommend playing and playing make u Chess ..............

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Article by: Joseph
    CONTENTS I.      What is a MOBA?   a. Definition   b. Origin   c. Current Generation II. The New Games   a. League of Legends   b. Heroes of Newerth   c. Dota 2   d. Smite III. Comparison IV. Conclusion ------------------------…
    See the related links at the bottom of the tutorial for downloads and supplemental information. Introduction The Nvidia 3D Vision Kit is a [not so] new gaming technology which allows you to play the newest computer games in "Stereo 3D" (like …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now