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
+15 -10

No files matched your search

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