bugfix: GetPinningRay function didn't start the ray from the king

This commit is contained in:
rektdie committed 2024-04-12 08:55:57 +02:00
1 parent ae581e0f03
commit fd5f070172
2 files changed
+16 -11

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ int main() {
Board board; Board board;
board.SetByFen("rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8"); board.SetByFen("rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8");
Perft(board, 2); Perft(board, 3);
return 0; return 0;
} }
+15 -10
View File
@@ -357,11 +357,12 @@ static Bitboard SliderRayToSquare(int attacker, int target) {
static Bitboard GetPinningRay(Board &board, int square, int direction) { static Bitboard GetPinningRay(Board &board, int square, int direction) {
Bitboard ray; Bitboard ray;
int previousRank = square / 8; int currentSquare = (board.pieces[King] & board.colors[board.sideToMove]).getLS1BIndex();
int previousRank = currentSquare / 8;
square += direction; currentSquare += direction;
while (square < 64 && square >= 0) { while (currentSquare < 64 && currentSquare >= 0) {
int currentRank = square / 8; int currentRank = currentSquare / 8;
int difference = abs(currentRank - previousRank); int difference = abs(currentRank - previousRank);
@@ -373,10 +374,14 @@ static Bitboard GetPinningRay(Board &board, int square, int direction) {
} }
previousRank = currentRank; previousRank = currentRank;
ray.SetBit(square); ray.SetBit(currentSquare);
if (board.occupied.IsSet(square)) { if (board.occupied.IsSet(currentSquare)) {
int attackerType = board.GetPieceType(square); if (currentSquare == square) {
int attackerColor = board.GetPieceColor(square); currentSquare += direction;
continue;
}
int attackerType = board.GetPieceType(currentSquare);
int attackerColor = board.GetPieceColor(currentSquare);
if (attackerColor != board.sideToMove) { if (attackerColor != board.sideToMove) {
// Pinned by rook or queen // Pinned by rook or queen
@@ -393,7 +398,7 @@ static Bitboard GetPinningRay(Board &board, int square, int direction) {
} }
break; break;
} }
square += direction; currentSquare += direction;
} }
return 0ULL; return 0ULL;
@@ -409,7 +414,7 @@ static bool IsPinned(Board &board, int square) {
& board.occupied).PopCount() != 2) { & board.occupied).PopCount() != 2) {
return false; return false;
} }
return GetPinningRay(board, square, -directionToKing).PopCount(); return GetPinningRay(board, square, -directionToKing).PopCount();
} }