diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-16 15:30:08 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2026-07-18 14:03:55 +0530 |
| commit | f1c6f59ae02a9d9db50171a69032dc2409a0e6c6 (patch) | |
| tree | 3c5d358f62a4d5925e8b768bcc3e79e9a7c9cf2c /src/engine/moves/attack.c | |
| parent | 1a52152852ff29c727673fc80e8bf8eca5ed6365 (diff) | |
magic bitboards via AI
Diffstat (limited to 'src/engine/moves/attack.c')
| -rw-r--r-- | src/engine/moves/attack.c | 92 |
1 files changed, 8 insertions, 84 deletions
diff --git a/src/engine/moves/attack.c b/src/engine/moves/attack.c index e4923ea..2786ad3 100644 --- a/src/engine/moves/attack.c +++ b/src/engine/moves/attack.c @@ -51,95 +51,19 @@ static bool sliding_attacks_square( bool check_bishop ) { bitboard_t all_occupied = whites(position) | blacks(position); - int rank = square / 8; - int file = square % 8; - - bitboard_t enemy_rooks = (by_color == WHITE_TURN) ? position.bitboards[WHITE_ROOK] : position.bitboards[BLACK_ROOK]; - bitboard_t enemy_bishops = (by_color == WHITE_TURN) ? position.bitboards[WHITE_BISHOP] : position.bitboards[BLACK_BISHOP]; - bitboard_t enemy_queens = (by_color == WHITE_TURN) ? position.bitboards[WHITE_QUEEN] : position.bitboards[BLACK_QUEEN]; if (check_rook) { - bitboard_t rook_like = enemy_rooks | enemy_queens; - - int r, idx; - r = rank + 1; - while (r < 8) { - idx = r * 8 + file; - if ((all_occupied >> idx) & 1) { - if ((rook_like >> idx) & 1) return true; - break; - } - r++; - } - r = rank - 1; - while (r >= 0) { - idx = r * 8 + file; - if ((all_occupied >> idx) & 1) { - if ((rook_like >> idx) & 1) return true; - break; - } - r--; - } - int f = file + 1; - while (f < 8) { - idx = rank * 8 + f; - if ((all_occupied >> idx) & 1) { - if ((rook_like >> idx) & 1) return true; - break; - } - f++; - } - f = file - 1; - while (f >= 0) { - idx = rank * 8 + f; - if ((all_occupied >> idx) & 1) { - if ((rook_like >> idx) & 1) return true; - break; - } - f--; - } + bitboard_t rook_like = (by_color == WHITE_TURN) + ? (position.bitboards[WHITE_ROOK] | position.bitboards[WHITE_QUEEN]) + : (position.bitboards[BLACK_ROOK] | position.bitboards[BLACK_QUEEN]); + if (get_rook_attacks(square, all_occupied) & rook_like) return true; } if (check_bishop) { - bitboard_t bishop_like = enemy_bishops | enemy_queens; - - int r, f, idx; - r = rank + 1; f = file + 1; - while (r < 8 && f < 8) { - idx = r * 8 + f; - if ((all_occupied >> idx) & 1) { - if ((bishop_like >> idx) & 1) return true; - break; - } - r++; f++; - } - r = rank - 1; f = file - 1; - while (r >= 0 && f >= 0) { - idx = r * 8 + f; - if ((all_occupied >> idx) & 1) { - if ((bishop_like >> idx) & 1) return true; - break; - } - r--; f--; - } - r = rank - 1; f = file + 1; - while (r >= 0 && f < 8) { - idx = r * 8 + f; - if ((all_occupied >> idx) & 1) { - if ((bishop_like >> idx) & 1) return true; - break; - } - r--; f++; - } - r = rank + 1; f = file - 1; - while (r < 8 && f >= 0) { - idx = r * 8 + f; - if ((all_occupied >> idx) & 1) { - if ((bishop_like >> idx) & 1) return true; - break; - } - r++; f--; - } + bitboard_t bishop_like = (by_color == WHITE_TURN) + ? (position.bitboards[WHITE_BISHOP] | position.bitboards[WHITE_QUEEN]) + : (position.bitboards[BLACK_BISHOP] | position.bitboards[BLACK_QUEEN]); + if (get_bishop_attacks(square, all_occupied) & bishop_like) return true; } return false; |
