[gnome-chess/gnome-3-8] Fix failure to detect past threefold repetitions
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess/gnome-3-8] Fix failure to detect past threefold repetitions
- Date: Sun, 11 Aug 2013 21:00:50 +0000 (UTC)
commit a19add550f9781fd1761068967ed62dadcb68d87
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 c896b61..2b4c0a6 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -1469,18 +1469,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]