bugfix: threefold repitition throws nullpointer

If the threefold repitition check is called before enough moves
are saved in the previous board state it throws a nullpointer.
A simple null check solves the problem
master
TiynGER 4 years ago
parent 91281d97a7
commit 5bee0f84d2

@ -810,6 +810,8 @@ proc isCheckmate*(game: Game, color: Color): bool =
proc threeMoveRep(game: Game): bool = proc threeMoveRep(game: Game): bool =
## Returns true if a 3-fold repitition happened on the last move of the ## Returns true if a 3-fold repitition happened on the last move of the
## `game`. ## `game`.
if game.previousBoard == []:
return false
var lastState = game.previousBoard[game.previousBoard.high] var lastState = game.previousBoard[game.previousBoard.high]
var lastCastleRights = game.previousCastleRights[game.previousBoard.high] var lastCastleRights = game.previousCastleRights[game.previousBoard.high]
var reps = 0 var reps = 0

Loading…
Cancel
Save