[gnome-chess] Fix failure to detect past threefold repetitions
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] Fix failure to detect past threefold repetitions
- Date: Sun, 11 Aug 2013 20:59:25 +0000 (UTC)
commit 4cabc410857685cfa2e27dc32572ee3e96480f68
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Aug 11 12:23:56 2013 -0500
Fix failure to detect past threefold repetitions
It's not enough to check if the current board state has been repeated
three times. We don't end games automatically for threefold repetition,
so it's possible to play past it. Calling the draw at any point
afterward should work.
src/chess-game.vala | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/src/chess-game.vala b/src/chess-game.vala
index c2a8f37..f65815e 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -1528,18 +1528,25 @@ public class ChessGame
private bool is_three_fold_repeat ()
{
+ foreach (var state in move_stack)
+ {
+ if (state_repeated_times (state) >= 3)
+ return true;
+ }
+
+ return false;
+ }
+
+ private int state_repeated_times (ChessState s1)
+ {
var count = 1;
- foreach (var state in move_stack.next)
+ foreach (var s2 in move_stack)
{
- if (current_state.equals (state))
- {
+ if (s1 != s2 && s1.equals (s2))
count++;
- if (count >= 3)
- return true;
- }
}
- return false;
+ return count;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]