[gnome-chess/mcatanzaro/#47: 1/2] threefold/fivefold repetition checks should consider only current state




commit 34b6e0dee49b0fc67b3b46129d3be2c2e0062e16
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Oct 14 12:36:59 2020 -0500

    threefold/fivefold repetition checks should consider only current state
    
    Way back in 4cabc410857685cfa2e27dc32572ee3e96480f68, I thought it was
    important to allow users to claim a draw at any point in the future
    after a threefold repetition. But this is not what the laws of chess
    allow: it should be claimed when it happens, not at random points in the
    future. At the time, that change probably made sense because we didn't
    tell the user when it's possible to claim a draw, which nowadays we do
    by opening a message dialog. But nowadays, it has no benefit, and a
    large cost: the message dialog appears at the start of every turn,
    forevermore, getting in the way and irritating the user. So let's only
    show it if the current board state really is eligible for a draw.
    
    Fixes #47

 lib/chess-game.vala | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
---
diff --git a/lib/chess-game.vala b/lib/chess-game.vala
index e7fdf05..154d252 100644
--- a/lib/chess-game.vala
+++ b/lib/chess-game.vala
@@ -247,25 +247,14 @@ public class ChessGame : Object
         return count;
     }
 
-    private bool is_n_fold_repeat (int n)
-    {
-        foreach (var state in move_stack)
-        {
-            if (state_repeated_times (state) >= n)
-                return true;
-        }
-
-        return false;
-    }
-
     public bool is_three_fold_repeat ()
     {
-        return is_n_fold_repeat (3);
+        return state_repeated_times (current_state) >= 3;
     }
 
     public bool is_five_fold_repeat ()
     {
-        return is_n_fold_repeat (5);
+        return state_repeated_times (current_state) >= 5;
     }
 
     public bool is_fifty_move_rule_fulfilled ()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]