Fix promotion bugs: all test positions from the wiki are now passing

This commit is contained in:
Mattia Giambirtone 2024-04-13 14:56:08 +02:00
parent 2ada052460
commit 6153112c21
1 changed files with 3 additions and 4 deletions

View File

@ -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()