Fix promotion bugs: all test positions from the wiki are now passing
This commit is contained in:
parent
032435e10e
commit
d7191e3e19
|
@ -1509,7 +1509,7 @@ proc doMove(self: ChessBoard, move: Move) =
|
||||||
castlingAvailable = self.position.castlingAvailable
|
castlingAvailable = self.position.castlingAvailable
|
||||||
enPassantTarget = emptyLocation()
|
enPassantTarget = emptyLocation()
|
||||||
# Needed to detect draw by the 50 move rule
|
# 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
|
halfMoveClock = 0
|
||||||
else:
|
else:
|
||||||
inc(halfMoveClock)
|
inc(halfMoveClock)
|
||||||
|
@ -1609,7 +1609,6 @@ proc doMove(self: ChessBoard, move: Move) =
|
||||||
# Make the en passant pawn disappear
|
# Make the en passant pawn disappear
|
||||||
self.removePiece(move.targetSquare + piece.color.bottomSide(), attack=false)
|
self.removePiece(move.targetSquare + piece.color.bottomSide(), attack=false)
|
||||||
|
|
||||||
|
|
||||||
if move.isCapture():
|
if move.isCapture():
|
||||||
# Get rid of captured pieces
|
# Get rid of captured pieces
|
||||||
self.removePiece(move.targetSquare, attack=false)
|
self.removePiece(move.targetSquare, attack=false)
|
||||||
|
@ -1618,6 +1617,7 @@ proc doMove(self: ChessBoard, move: Move) =
|
||||||
if move.isPromotion():
|
if move.isPromotion():
|
||||||
# Move is a pawn promotion: get rid of the pawn
|
# Move is a pawn promotion: get rid of the pawn
|
||||||
# and spawn a new piece
|
# and spawn a new piece
|
||||||
|
self.removePiece(move.targetSquare)
|
||||||
case move.getPromotionType():
|
case move.getPromotionType():
|
||||||
of PromoteToBishop:
|
of PromoteToBishop:
|
||||||
self.spawnPiece(move.targetSquare, Piece(kind: Bishop, color: piece.color))
|
self.spawnPiece(move.targetSquare, Piece(kind: Bishop, color: piece.color))
|
||||||
|
@ -1628,10 +1628,9 @@ proc doMove(self: ChessBoard, move: Move) =
|
||||||
of PromoteToQueen:
|
of PromoteToQueen:
|
||||||
self.spawnPiece(move.targetSquare, Piece(kind: Queen, color: piece.color))
|
self.spawnPiece(move.targetSquare, Piece(kind: Queen, color: piece.color))
|
||||||
else:
|
else:
|
||||||
|
# Unreachable
|
||||||
discard
|
discard
|
||||||
self.updateAttackedSquares()
|
self.updateAttackedSquares()
|
||||||
# TODO: Remove this, once I figure out what the heck is wrong
|
|
||||||
# with updating the board representation
|
|
||||||
self.updateBoard()
|
self.updateBoard()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue