diff --git a/Chess/nimfish/nimfishpkg/position.nim b/Chess/nimfish/nimfishpkg/position.nim index f43b119..a686e56 100644 --- a/Chess/nimfish/nimfishpkg/position.nim +++ b/Chess/nimfish/nimfishpkg/position.nim @@ -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 diff --git a/Chess/nimfish/nimfishpkg/see.nim b/Chess/nimfish/nimfishpkg/see.nim index 937a710..02cee88 100644 --- a/Chess/nimfish/nimfishpkg/see.nim +++ b/Chess/nimfish/nimfishpkg/see.nim @@ -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():