miguel-ambrona / D3-Chess

Chess Unwinnability Analyzer is an implementation of a decision procedure for checking whether there exists a sequence of legal moves that allows a certain player to checkmate their opponent in a given chess position.
https://chasolver.org
GNU General Public License v3.0
51 stars 8 forks source link

Forced draw for fivefold repetition and seventy-five move rule not considered #3

Closed dlbbld closed 3 years ago

dlbbld commented 3 years ago

Hi

Neither the moves nor the half-move clock are supplied to CHA, so it does not consider fivefold repetition and the seventy-five move rule.

In the following game, CHA will indicate a possible win for White, which is incorrect for the fivefold repetition rule.

[Event "?"] [Site "?"] [Date "????.??.??"] [Round "?"] [White "?"] [Black "?"] [Result "*"] [SetUp "1"] [FEN "6Qk/8/2R3K1/8/8/8/8/8 b - - 0 3"]

3... Kxg8 4. Kh6 Kh8 5. Kg6 Kg8 6. Kh6 Kh8 7. Kg6 Kg8 8. Kh6 Kh8 9. Kg6 Kg8 10. Kh6 Kh8 11. Kg6 *

The fivefold repetition 3... Kxg8 5... Kg8 7...Kg8 9... Kg8 11... Kg8 is forced, so the only possible game outcome is a draw.

Now a similar situation for the seventy-five-move rule.

7k/8/2R3K1/8/8/8/8/8 b - - 149 100

Seventy-five moves each without pawn moves and capture are inevitable with Kg8. So the only possible game outcome is a draw, but CHA indicating a possible win for White.

How do you look at this? CHA is not sound for this reason. But I think it is from an algorithmic view not complicated to add these options. When constructing the helpmate series, checking the repetition counter and half-move clock in principle should do.

Or are there more difficulties related to this?

miguel-ambrona commented 3 years ago

I understand your point. I ignored that case for simplicity and would be happy to adapt the tool if you can find a good application of it.

Note that the fivefold repetition or seventy-five-move rule do not apply when a player runs out of time (and Article 6.9 of the FIDE Laws of Chess needs to be applied).

dlbbld commented 3 years ago

The observation belongs to the scope of CHA. The two examples are possible real games. Both are "unwinnable" by White, but CHA declares both as winnable. The reason is not considering articles 9.6.1 and 9.6.2. The below reply is now very long, for explaining in detail my point that article 6.9 includes 9.6.1 and 9.6.2.

Note that the fivefold repetition or seventy-five-move rule do not apply when a player runs out of time (and Article 6.9 of the FIDE Laws of Chess needs to be applied).

I'm afraid I have to disagree with this understanding. Article 6.9 looks at the possible continuations for the game to decide if it's a draw or a loss. So all rules apply. Article 6.9 requires the context of a game. To look at the last sentence of 6.9 as an abstract statement detached from the game does not make sense to me. It is something which one only formally can do and not intended by the creators. If you look at all FIDE rules in this formal way and detach them entirely from the game context, not one chess game is possible.

I refer to the following comment after article 6.9 in the arbiters manual. "Also in the case of articles 9.6.1 and 9.6.2, even if a player does not complete the prescribed number of moves in the allotted time, the game is drawn." If a player flags after 150 half-moves completed without pawn move and capture, the game is a draw. The comment explicitly refers to 9.6.2 on timeout. So there is no indication of any intention to ignore 9.6.1, 9.6.2 or any other rules when assessing 6.9.

Notably, this means that also the threefold repetition rule and the fifty-move rule apply when evaluating 6.9. So, for example, in a KBNvK endgame, a possible win after 120 half-moves is taken into account. The player with the lone king can but must not claim the draw according to the fifty-move rule at this stage. So this win is a possible legal series of moves for the game. It counts for evaluating 6.9. The fifty-move rule is taken into account for evaluating 6.9, as any other rule, but has no impact.

A checkmate in KBNvK after 151 half-moves without pawn move and capture is not a possible game outcome. This legal series of moves is not a possible legal series of moves for the game, so it does not count for evaluating 6.9. The reason is that after 150 such half-moves, the game terminates per 9.6.1. The result is a win for White, if checkmate, otherwise a draw.

For example, if for KBNvK, the Black player flags after 140 half-moves without pawn move and capture, and there is no helpmate within ten half-moves, the game is a draw. More precisely, it is already a draw when White cannot mate within the 150 half-moves for being a dead position. But CHA will always declare KBNvK as "winnable" for White. It does not consider the half-move clock, which leads to wrong results in some cases.

Now, this turned into a detailed look at the rules. To resume, per my opinion, 9.6.1 and 9.6.2 must be considered for evaluating 6.9, and the consideration can change the outcome. Please consider the above arguments and explain where and why you come to different conclusions in the case.

miguel-ambrona commented 3 years ago

Article 6.9 of the FIDE Laws of Chess reads as follows:

... if a player does not complete the prescribed number of moves in the allotted time, the game is lost by the player. However, the game is drawn, if the position is such that the opponent cannot checkmate the player’s king by any possible series of legal moves.

Observe that the second sentence refers to "the position". This term is ambiguous, admits different interpretations and is probably the reason for our disagreement. I choose to interpret "the position" as the current state of the board pieces, ignoring the halfmove clock and the repeated positions during the game (which cannot be encoded with a standard FEN description). (Note that these extra notions only exist to ensure termination of a chess game, but in our case the game has already finished.) I guess that in the incredibly unlikely event that the halfmove clock or fivefold repetition affect the "unwinnability" property of the position, the arbiter would have the last word about how to interpret Article 6.9.

Again, I think capturing those properties with our current tool is very simple from an algorithmic point of view. The most involved part would be to design a mechanism for parsing the desired position (probably reading the full PGN would be best). If you want to give it a try and extend the tool in a clean way to support this, I would be happy to accept your pull request.

dlbbld commented 3 years ago

From a practical view, this discussion is much easier.

The relevant part of 6.9 again:

However, the game is drawn if the position is such that the opponent cannot checkmate the player's king by any possible series of legal moves.

There is no doubt from a practical view that when speaking of "opponent" and "players's king" this refers to an ongoing game. Alone, when speaking of a "position" abstractly, there is no "opponent", no "player's king", there is just the position. In my view, this is already enough. FIDE rules are not a mathematical book.

The apparent intention of the rule is simply that, for example, in KvKR, if Black flags, White is not awarded more than is possible in the game. The rule also discourages time play, so not favouring situations that potentially could bring chess into disrepute.

Now there is a twist here, which leads to the final different outcome.

When looking at the position only, one does not limit the number of moves for evaluating possible checkmate etc.

And before introducing the fivefold repetition and seventy-five-move rule 2014, chess games had no limit in length. So it did not matter if looking at the position abstractly or the game from the position.

With the introduction of the two rules, chess games became finite. So now it makes a difference if looking at the position abstractly or the game from the position. In the first one can make as many moves as one likes. In the second, the potential number of moves is limited.

Strictly looking at the position in the abstract sense was never correct but had no impact. But now, when insisting on this interpretation, it is not anymore with the intention of the rule.

So practically, if one agrees that the intent of the rules is not to award a Win to a player if the opponent is flagging and the player could not have won the game, this interpretation is not correct.

I go with this intention of the rules, so I have to disagree with looking at the position only discarding the repetition count and the half-move clock.

The first point is here to be clear what a tool like CHA is trying to achieve! So please consider the above point and explain if you can uphold your interpretation along with the mentioned points.

dlbbld commented 3 years ago

For the other part, thanks for the suggestion regarding the pull request. Both from the topic and language I lack experience, so I don't foresee this. It requires the PGN for the fivefold repetition rule, so a PGN reader, that should not be a problem.