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
master
TiynGER 4 years ago
parent 5e796751d7
commit 23a97ae9fe

@ -792,10 +792,13 @@ proc checkedMove*(chess: var Chess, move: Move): bool {.discardable.} =
chess.uncheckedMove(start, dest) chess.uncheckedMove(start, dest)
chess.toMove = Color(ord(chess.toMove)*(-1)) chess.toMove = Color(ord(chess.toMove)*(-1))
if createEnPassant: if createEnPassant:
if chess.board[dest + E] == BPawn * ord(color) or
chess.board[dest + W] == BPawn * ord(color):
chess.enPassantSquare = dest - (N * ord(color)) chess.enPassantSquare = dest - (N * ord(color))
if capturedEnPassant: if capturedEnPassant:
chess.board[dest - (N * ord(color))] = 0 chess.board[dest - (N * ord(color))] = 0
if ((fieldToInd("h8") < dest and dest < fieldToInd("a8")) or (fieldToInd("h1") < dest and dest < fieldToInd("a1"))) and 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] == WPawn * ord(color):
chess.board[dest] = prom chess.board[dest] = prom
chess.previousBoard.add(chess.board) chess.previousBoard.add(chess.board)

Loading…
Cancel
Save