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