Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threefold repetition checking #144

Closed
inmylo opened this issue Mar 1, 2017 · 4 comments
Closed

Threefold repetition checking #144

inmylo opened this issue Mar 1, 2017 · 4 comments

Comments

@inmylo
Copy link

inmylo commented Mar 1, 2017

in_threefold_repetition() returns true when the same position has repeated 3+ times, but if after that I make absolutely another moves, the opponent too, in_threefold_repetition() still returns true.

I'm not sure that this behavior is by the chess rules. I think the result should be false when the position has changed

@jhlywa
Copy link
Owner

jhlywa commented Mar 11, 2017

Hi @Imilo. Thanks for the report. I think you're correct. Using FIDE rule 9.2 as a reference:

The game is drawn, upon a correct claim by a player having the move, when the same 
position for at least the third time (not necessarily by a repetition of moves):

- is about to appear, if he first writes his move, which cannot be changed, on his
  scoresheet and declares to the arbiter his intention to make this move, or

- has just appeared, and the player claiming the draw has the move.

So maybe we should change the code so in_threefold_repetition() returns true if and only if the current position has been repeated three times?

@jhlywa jhlywa added this to the 0.11.0 milestone Mar 11, 2017
@inmylo
Copy link
Author

inmylo commented Mar 11, 2017

@jhlywa , if that question was for me, that's a tricky question...

For example, if I make a position that has appeared 3+ times -> in_threefold_repetition() will return True a that moment. But my opponent can make his new unique move very quickly -> position will be changed -> in_threefold_repetition() will return False for me. So I will lose my chance to claim for a draw.

chess.js should handle this somehow. JavaScript could remember that I can claim for a draw until my next move, so we don't care about the opponent's move. These are my thoughts, may be you have a better solution

@jhlywa jhlywa modified the milestones: 0.11.0, 0.12.0 Jan 19, 2018
@dsjoerg
Copy link

dsjoerg commented Mar 19, 2018

@Imilo you make a good point. I think we should change in_threefold_repetition() to return true only if the current_position has appeared for at least the third time. That way we match FIDE rules. @jhlywa if you're OK with this I'll submit a PR for your approval.

@Imilo I like your suggestion that Javascript can remember that you can claim for a draw until your next move. That's not the FIDE rule, but you can make it that way for your own chess site even if chess.js is strictly following the FIDE rules. You could do it like this:

if (players_turn) {
  if (game.in_threefold_repetition()) {
    // show "Claim Draw" button to the player
  } else {
    // check and see if our last move created a threefold repetition so that we could have claimed a draw.
    var move = game.pop()   // undo the opponent's move
    if (game.in_threefold_repetition()) {
      // show "Claim Draw" button to the player
    }
    game.make_move(move)
  }
}

@ajax333221
Copy link

This bug propagates to chess.game_over() and chess.in_draw() returning true, as others have said it should check for the current position vs older positions.

This should be labeled as a bug in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants