From 6153112c21738497047cb7a41de79cd8616682f1 Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Sat, 13 Apr 2024 14:56:08 +0200 Subject: [PATCH] Fix promotion bugs: all test positions from the wiki are now passing --- src/Chess/board.nim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Chess/board.nim b/src/Chess/board.nim index 1e55d21..cfd08dd 100644 --- a/src/Chess/board.nim +++ b/src/Chess/board.nim @@ -1509,7 +1509,7 @@ proc doMove(self: ChessBoard, move: Move) = castlingAvailable = self.position.castlingAvailable enPassantTarget = emptyLocation() # Needed to detect draw by the 50 move rule - if piece.kind == Pawn or move.isCapture(): + if piece.kind == Pawn or move.isCapture() or move.isEnPassant(): halfMoveClock = 0 else: inc(halfMoveClock) @@ -1609,7 +1609,6 @@ proc doMove(self: ChessBoard, move: Move) = # Make the en passant pawn disappear self.removePiece(move.targetSquare + piece.color.bottomSide(), attack=false) - if move.isCapture(): # Get rid of captured pieces self.removePiece(move.targetSquare, attack=false) @@ -1618,6 +1617,7 @@ proc doMove(self: ChessBoard, move: Move) = if move.isPromotion(): # Move is a pawn promotion: get rid of the pawn # and spawn a new piece + self.removePiece(move.targetSquare) case move.getPromotionType(): of PromoteToBishop: self.spawnPiece(move.targetSquare, Piece(kind: Bishop, color: piece.color)) @@ -1628,10 +1628,9 @@ proc doMove(self: ChessBoard, move: Move) = of PromoteToQueen: self.spawnPiece(move.targetSquare, Piece(kind: Queen, color: piece.color)) else: + # Unreachable discard self.updateAttackedSquares() - # TODO: Remove this, once I figure out what the heck is wrong - # with updating the board representation self.updateBoard()