6

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.

Specifically:

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

Edit:

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
10

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.

3

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
1

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.

0

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.

-1

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.

Your understanding is wrong. Both checkmate and stalemate take effect immediately the move has been made. The move is made immediately the player's hand loses contact with the piece. It happens even before the player presses the clock. Hence even if the player's flag falls the checkmate or stalemate still stands.

In your terminology both cause the game to end before the opponent's next phase.

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

FIDE is the international chess federation. It stands for "Federation International des Echecs" and is French for "International Chess Federation". It is the chess equivalent of FIFA in the world of soccer. If you understand that the FIFA rules of soccer govern the play of soccer throughout the world then you will also understand that the FIDE Laws of Chess govern the play of chess throughout the world.

Individual chess federations (governing bodies of national chess federations) may vary some rules in special cases but when they do so the tournaments affected can not be internationally rated. They can only be nationally rated.

The most common variation that I am aware of is that for competitions for weak/young players the rule which says that two illegal moves loses the game is suspended because these players play many illegal moves without thinking.

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