I'm not enthusiastic about chess in particular, so if I use terminology incorrectly please correct me. I use "phase 1 & phase 2" for each player's move, and "turn n" for each pair of phases.

I'm a novice programmer writing a chess program as a personal challenge, and would like to know exactly when checkmates and stalemates take effect.


  • If a player 1's move causes checkmate or stalemate, does the game end during phase 1, or at the beginning of phase 2?


It seems I wasn't clear enough that I wasn't looking for a programming answer, I wanted to know about chess standards. Even if my program can work without detecting the exact final phase, I would like that information to be available.

I looked at the FIDE rules as mentioned in Laska 's answer [link], and Section 5 points out what I was looking for:

  • 5.1 a. The game is won by the player who has checkmated his opponent’s king. This immediately ends the game, provided that the move producing the checkmate position was a legal move.

  • 5.2 a. The game is drawn when the player to move has no legal move and his king is not in check. The game is said to end in ‘stalemate’. This immediately ends the game, provided that the move producing the stalemate position was legal.

From these rules I gather that if I cause a checkmate, the game ends before my opponent's next phase, and if I cause a stalemate, the game ends during my opponent's next phase.

Please correct me if you think I'm not understanding something correctly. Also, I know I've seen the term FIDE before but I'm not sure if their chess laws would generally be considered a widely accepted and robust standard. I figure a chess community is the right place to ask about whether or not I should be using their standards.

  • The quoted checkmate and stalemate rules both use the phrase: "immediately ends the game." You might want to expand your question to indicate why they might be treated differently. – D Krueger Apr 10 at 3:38

Take your pick.

Conventionally in computer chess, we express your idea of phases as "plies", or half-moves, where 2 plies is one "turn".

You can detect checkmate in the ply where the checkmating move is made, but it is more common for checkmate to be detected in the following ply, where your program generates legal moves for the mated player, only to find that there are 0 available.

It is often more convenient and efficient that way, as the work to generate moves would have been done anyway had the position not been mate, so no extra work is done to determine whether a position is checkmate.


Thanks for the question.

The FIDE rules are not great here. A turn ends when a game-ending move has been played (Article 6.2.a.1). The clock does not need to be pressed. But in order to compute whether the move ends the game, there has to have been some kind of hypothetical look-ahead as to what would happen at the beginning of the next turn. The simple purpose of this I suppose is to avoid the chance to lose on time after just having e.g. played a mating move.

A particular question is who has the move in the final position? In cases of mate it’s sort of obvious but in cases of stalemate it is not clear at all. Is this showing the position in the actual time or the position in the hypothetical look-ahead? Argh!

However from a programming point of view this hypothecating is not necessary. The move is completed, and the opponent loses or is stalemated etc in their own turn. The final position cleanly shows who has the move.

  • Nobody has the move, as the game is over. But if it weren't, it'd be the opponent who has the move, after all the checkmating move has been made, and that means the other side has the move. What happens to the clock is relatively unimportant. – RemcoGerlich Mar 25 at 12:18
  • Hi @RemcoGerlich thanks for the thoughtful response. I had wondered about whether the game ending annihilates the information about who has the move. But if I can no longer tell who has the move following a stalemate then I probably can't confirm that the game is actually over! We've erased some rather necessary information. So this kind of amnesia can't occur after stalemate, and by analogy won't occur after checkmate. And hence I agree with your second point that its the checkmated (or stalemated) player who has the move in the final position. – Laska Mar 26 at 15:33

Checkmate and stalemate end the game immediately, as soon as the move is played (that is, when the hand lets go of the piece -- but that's not relevant for computers).

If that move was white's, then that move was the last move of the game. Black never gets their turn, so in your terms "phase 2" of that turn doesn't exist.


There is no reason not to exit the loops your programm uses after a checkmate or a stalemate. The rules of the game says there is no move for the oponnent. The game is finished.

You should just break your looping and send an alert with the result and update the statics of your programm.

There is not any .pgn or FEN more notation to write so no sense to still use code to perform your programm.

protected by Phonon Mar 23 at 11:31

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.