bugfix: Checkers function, added: helper functions to detect partial pins in the future

This commit is contained in:
rektdie committed 2024-04-08 09:19:23 +02:00
1 parent 3a7531cd3d
commit 70179b953d
2 files changed
+30 -21

No files matched your search

+29 -20
View File
@@ -309,7 +309,7 @@ static Bitboard Checkers(Board &board, bool color) {
for (int type = Pawn; type < King; type++) { for (int type = Pawn; type < King; type++) {
Bitboard targets = getPieceAttacks(kingSquare, type, color, board.occupied.GetBoard()); Bitboard targets = getPieceAttacks(kingSquare, type, color, board.occupied.GetBoard());
checkerBoard |= targets & board.pieces[type]; checkerBoard |= targets & board.pieces[type] & board.colors[!color];
} }
return checkerBoard; return checkerBoard;
} }
@@ -357,30 +357,40 @@ static Bitboard SliderRaysToSquare(int attacker, int target) {
return ray; return ray;
} }
static Bitboard GetPinningRay(Board &board, int square, int direction) {
Bitboard ray;
if (direction) {
while (square < 64 && square >= 0) {
ray.SetBit(square);
if (board.occupied.IsSet(square)) {
int attackerColor = board.GetPieceColor(square);
int attackerType = board.GetPieceType(square);
if (attackerColor == !board.sideToMove && (attackerType == Rook
|| attackerType == Bishop || attackerType == Queen)) {
return ray;
}
return 0ULL;
}
square += direction;
}
}
return 0ULL;
}
static bool IsPinned(Board &board, int square, int color) { static bool IsPinned(Board &board, int square, int color) {
int kingSquare = (board.colors[color] & board.pieces[King]).getLS1BIndex(); int kingSquare = (board.colors[color] & board.pieces[King]).getLS1BIndex();
int directionToKing = GetDirection(square, kingSquare); int directionToKing = GetDirection(square, kingSquare);
int currentSquare = square - directionToKing; if (SliderRaysToSquare(square, kingSquare).PopCount() != 2) {
bool pinner = false; return false;
if (directionToKing) {
while (currentSquare < 64 && currentSquare >= 0) {
if (board.occupied.IsSet(currentSquare)) {
int attackerColor = board.GetPieceColor(currentSquare);
int attackerType = board.GetPieceType(currentSquare);
if (attackerColor == !color && (attackerType == Rook
|| attackerType == Bishop || attackerType == Queen)) {
pinner = true;
}
break;
}
currentSquare += -directionToKing;
}
} }
return pinner; int currentSquare = square - directionToKing;
return GetPinningRay(board, currentSquare, -directionToKing).GetBoard();
} }
static void GenPawnMoves(Board &board, bool color) { static void GenPawnMoves(Board &board, bool color) {
@@ -437,7 +447,6 @@ static void GenCheckEvasions(Board &board, bool color) {
Bitboard captureMask = Checkers(board, color); // Checker locations Bitboard captureMask = Checkers(board, color); // Checker locations
Bitboard pushMask; // Where blockers can move to Bitboard pushMask; // Where blockers can move to
if (captureMask.PopCount() == 1) { if (captureMask.PopCount() == 1) {
int checkerSquare = captureMask.getLS1BIndex(); int checkerSquare = captureMask.getLS1BIndex();
int checkerType = board.GetPieceType(checkerSquare); int checkerType = board.GetPieceType(checkerSquare);
+1 -1
View File
@@ -4,7 +4,7 @@
using U64 = uint64_t; using U64 = uint64_t;
constexpr char StartingFen[] = "8/8/8/8/r2K4/2P5/8/b6k w - - 0 1"; constexpr char StartingFen[] = "8/8/8/8/r2K4/2P5/8zz/b6k w - - 0 1";
enum COLOR { enum COLOR {
White, White,