Fix SEE bugs and ensure getKingAttacks works even if the king is removed from the board
This commit is contained in:
parent
2c840f2f3c
commit
7fcdf25dbb
|
@ -113,14 +113,18 @@ func getPawnAttacks*(self: Position, square: Square, attacker: PieceColor): Bitb
|
|||
return self.getBitboard(Pawn, attacker) and getPawnAttacks(attacker, square)
|
||||
|
||||
|
||||
func getKingAttacks*(self: Position, square: Square, attacker: PieceColor): Bitboard {.inline.} =
|
||||
proc getKingAttacks*(self: Position, square: Square, attacker: PieceColor): Bitboard {.inline.} =
|
||||
## Returns the location of the king if it is attacking the given square
|
||||
result = Bitboard(0)
|
||||
let king = self.getBitboard(King, attacker)
|
||||
if king == 0:
|
||||
# The king was removed (probably by SEE or some
|
||||
# other internal machinery). This should never
|
||||
# occur during normal movegen!
|
||||
return
|
||||
if (getKingAttacks(king.toSquare()) and square.toBitboard()) != 0:
|
||||
return king
|
||||
|
||||
|
||||
func getKnightAttacks*(self: Position, square: Square, attacker: PieceColor): Bitboard =
|
||||
## Returns the locations of the knights attacking the given square
|
||||
let
|
||||
|
|
|
@ -101,9 +101,10 @@ proc see(position: Position, square: Square): int =
|
|||
let
|
||||
epTarget = position.enPassantSquare.toBitboard()
|
||||
epPawn = epTarget.backwardRelativeTo(sideToMove).toSquare()
|
||||
victimPiece = position.getPiece(epPawn)
|
||||
victim = victimPiece.getStaticPieceScore()
|
||||
position.removePiece(epPawn)
|
||||
if position.getPiece(epPawn) != nullPiece():
|
||||
victimPiece = position.getPiece(epPawn)
|
||||
victim = victimPiece.getStaticPieceScore()
|
||||
position.removePiece(epPawn)
|
||||
|
||||
# Capture with promotion
|
||||
if attackerPiece.kind == Pawn and getRankMask(rankFromSquare(square)) == attackerPiece.color.getLastRank():
|
||||
|
|
Loading…
Reference in New Issue