From 5bee0f84d2b6a83e2d64f59a29963e72ad77a81a Mon Sep 17 00:00:00 2001 From: TiynGER Date: Sat, 1 May 2021 01:54:16 +0200 Subject: [PATCH] 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 --- src/chess.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/chess.nim b/src/chess.nim index d7482f6..3ec4543 100644 --- a/src/chess.nim +++ b/src/chess.nim @@ -810,6 +810,8 @@ proc isCheckmate*(game: Game, color: Color): bool = proc threeMoveRep(game: Game): bool = ## Returns true if a 3-fold repitition happened on the last move of the ## `game`. + if game.previousBoard == []: + return false var lastState = game.previousBoard[game.previousBoard.high] var lastCastleRights = game.previousCastleRights[game.previousBoard.high] var reps = 0