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.
This commit is contained in:
Michael Catanzaro 2013-08-11 12:23:56 -05:00
parent d49c7d8cae
commit 4cabc41085

View file

@ -1528,18 +1528,25 @@ public class ChessGame
private bool is_three_fold_repeat ()
{
var count = 1;
foreach (var state in move_stack.next)
foreach (var state in move_stack)
{
if (current_state.equals (state))
{
count++;
if (count >= 3)
return true;
}
if (state_repeated_times (state) >= 3)
return true;
}
return false;
}
private int state_repeated_times (ChessState s1)
{
var count = 1;
foreach (var s2 in move_stack)
{
if (s1 != s2 && s1.equals (s2))
count++;
}
return count;
}
}