From 23a97ae9fecc15cac8c80ad74342549e130560ee Mon Sep 17 00:00:00 2001 From: TiynGER Date: Tue, 11 May 2021 01:42:20 +0200 Subject: [PATCH] chess bugfix: en passant square creation The en passant square is only important if it is target of an enemy pawn. If that is not the case it should not be set and shouldn't appear in the fen string either. Now it is checked if the en passant square is the target of an enemy pawn --- src/chess.nim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chess.nim b/src/chess.nim index 412aef5..4d0908b 100644 --- a/src/chess.nim +++ b/src/chess.nim @@ -792,11 +792,14 @@ proc checkedMove*(chess: var Chess, move: Move): bool {.discardable.} = chess.uncheckedMove(start, dest) chess.toMove = Color(ord(chess.toMove)*(-1)) if createEnPassant: - chess.enPassantSquare = dest - (N * ord(color)) + if chess.board[dest + E] == BPawn * ord(color) or + chess.board[dest + W] == BPawn * ord(color): + chess.enPassantSquare = dest - (N * ord(color)) if capturedEnPassant: chess.board[dest - (N * ord(color))] = 0 - if ((fieldToInd("h8") < dest and dest < fieldToInd("a8")) or (fieldToInd("h1") < dest and dest < fieldToInd("a1"))) and - chess.board[dest] == WPawn * ord(color): + if ((fieldToInd("h8") < dest and dest < fieldToInd("a8")) or + (fieldToInd("h1") < dest and dest < fieldToInd("a1"))) and + chess.board[dest] == WPawn * ord(color): chess.board[dest] = prom chess.previousBoard.add(chess.board) chess.halfMoveClock = chess.halfMoveClock + 1