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:
parent
d49c7d8cae
commit
4cabc41085
1 changed files with 16 additions and 9 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue