bugfix: isLegalEnPassant function returned wrong values
This commit is contained in:
1 parent
83b514b300
commit
34d689fda2
2 files changed
+17
-29
No files matched your search
+1
-1
@@ -10,7 +10,7 @@ int main() {
|
||||
|
||||
Board board;
|
||||
board.SetByFen("r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1");
|
||||
Perft(board, 4);
|
||||
Perft(board, 5);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+16
-28
@@ -436,39 +436,27 @@ static bool IsLegalEnPassant(Board &board, int square) {
|
||||
newOccupancy.PopBit(board.enPassantTarget - pushDirection);
|
||||
|
||||
// Looking for horizontal checks
|
||||
if (!(kingSquare.GetBoard() & files[A])) {
|
||||
int currentSq = kingSquare.getLS1BIndex() + west;
|
||||
int directionToKing = GetDirection(square, kingSquare.getLS1BIndex());
|
||||
|
||||
while (!Bitboard(files[H]).IsSet(currentSq)) {
|
||||
// Either east or west
|
||||
if (abs(directionToKing) == 1) {
|
||||
int currentSq = square - directionToKing;
|
||||
|
||||
Bitboard endingFile = directionToKing > 0 ? files[H] : files[A];
|
||||
|
||||
while (!endingFile.IsSet(currentSq)) {
|
||||
if (newOccupancy.IsSet(currentSq)) {
|
||||
int attackerColor = board.GetPieceColor(currentSq);
|
||||
int attackerType = board.GetPieceType(currentSq);
|
||||
int squareColor = board.GetPieceColor(currentSq);
|
||||
int squarePiece = board.GetPieceType(currentSq);
|
||||
|
||||
if (attackerColor != board.sideToMove && (attackerType == Rook
|
||||
|| attackerType == Bishop || attackerType == Queen)) {
|
||||
return false;
|
||||
if (squareColor != board.sideToMove) {
|
||||
if (squarePiece == Rook || squarePiece == Queen) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
currentSq += west;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(kingSquare.GetBoard() & files[H])) {
|
||||
int currentSq = kingSquare.getLS1BIndex() + east;
|
||||
|
||||
while (!Bitboard(files[A]).IsSet(currentSq)) {
|
||||
if (newOccupancy.IsSet(currentSq)) {
|
||||
int attackerColor = board.GetPieceColor(currentSq);
|
||||
int attackerType = board.GetPieceType(currentSq);
|
||||
|
||||
if (attackerColor != board.sideToMove && (attackerType == Rook
|
||||
|| attackerType == Bishop || attackerType == Queen)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
currentSq += east;
|
||||
currentSq -= directionToKing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user