954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Chess- Check Mate suggestion

Hello Everyone,
I am writing chess code in C++ using a main cpp file and functions only.. SO basically am done with everything except the checkmate condition... the only conditions for checkmate i have checked are the movements that king can make.. but there might be other possibilities of saving from the check like moving other pieces.. So any suggestions on how to implement :/... I would really appreciate any help..

Thanks in Advance

misalazeem
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

I think you'd have to first check to see if there are any possible moves your king can make... and then if the attacking piece is not a knight, you will probably have to check every other piece on the board to see if it can move anywhere inside the line of the attacking piece and the king. lastly, every piece should be tested to see if it can actually kill the attacking piece.

if the king cannot make a legal move, and the attacking piece is a knight, then the only possible scenario is a checkmate (unless the knight itself can be taken.) No block can occur.

When all three conditions occur; no legal move for king, no block can occur, and the attacking piece cannot be taken, only then can you conclude checkmate.

Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118
 

There are four conditions that must be met for checkmate to occur:

1) The king is in check.
2) There is no move that the king can make that takes it out of check.
3) It is not possible to capture the attacking piece.
4) It is not possible to interpose a piece between the king and the attacking piece.

(3) and (4) are impossible if there is more than one attacking piece.
(4) is impossible if the attacking piece is a knight.

arkoenig
Master Poster
703 posts since Jun 2010
Reputation Points: 359
Solved Threads: 109
 

Thanks alot guys.. found it really helpful... :)

misalazeem
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

What about the following scenario?

1) Your king is not in check.
2) It's your move and any move you make places your king into check.

Is that checkmate?

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

What about the following scenario?

1) Your king is not in check. 2) It's your move and any move you make places your king into check.

Is that checkmate?


No. It's stalemate, and the game is drawn.

arkoenig
Master Poster
703 posts since Jun 2010
Reputation Points: 359
Solved Threads: 109
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You