detecting checkmate

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?
Who is Participating?
Those are the only way of getting out of check.
You cannot castle out of check.
☠ MASQ ☠Commented:
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
Derek JensenCommented:
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.

(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
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 ..............
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.