summaryrefslogtreecommitdiff
path: root/src/engine/moves/bishop.c
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-07-16 15:30:08 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-07-18 14:03:55 +0530
commitf1c6f59ae02a9d9db50171a69032dc2409a0e6c6 (patch)
tree3c5d358f62a4d5925e8b768bcc3e79e9a7c9cf2c /src/engine/moves/bishop.c
parent1a52152852ff29c727673fc80e8bf8eca5ed6365 (diff)
magic bitboards via AI
Diffstat (limited to 'src/engine/moves/bishop.c')
-rw-r--r--src/engine/moves/bishop.c49
1 files changed, 6 insertions, 43 deletions
diff --git a/src/engine/moves/bishop.c b/src/engine/moves/bishop.c
index 0bc47f8..a7b2812 100644
--- a/src/engine/moves/bishop.c
+++ b/src/engine/moves/bishop.c
@@ -7,52 +7,15 @@ void __forloop_bishop_moves_gen(
bitboard_t friendly_pieces,
bitboard_t enemy_pieces
) {
+ bitboard_t all_occupied = friendly_pieces | enemy_pieces;
while (friendly_type) {
int from = __builtin_ctzll(friendly_type);
friendly_type &= friendly_type - 1;
-
- int og_rank = from / 8; // range: [0, 7]
- int og_file = from % 8; // range: [0, 7]
- int rank = og_rank + 1, file = og_file + 1, index = rank * 8 + file;
-
- bitboard_t occupied;
- while ((rank < 8 && file < 8) && !occupied_by(friendly_pieces, index)) {
- occupied = occupied_by(enemy_pieces, index);
- add_move(moves, from, index, .flags = occupied ? MOVE_CAPTURE : 0);
- if (occupied) {
- break;
- }
- index = ++rank * 8 + ++file;
- }
-
- rank = og_rank - 1, file = og_file - 1, index = rank * 8 + file;
- while ((rank >= 0 && file >= 0) && !occupied_by(friendly_pieces, index)) {
- occupied = occupied_by(enemy_pieces, index);
- add_move(moves, from, index, .flags = occupied ? MOVE_CAPTURE : 0);
- if (occupied) {
- break;
- }
- index = --rank * 8 + --file;
- }
-
- rank = og_rank - 1, file = og_file + 1, index = rank * 8 + file;
- while ((rank >= 0 && file < 8) && !occupied_by(friendly_pieces, index)) {
- occupied = occupied_by(enemy_pieces, index);
- add_move(moves, from, index, .flags = occupied ? MOVE_CAPTURE : 0);
- if (occupied) {
- break;
- }
- index = --rank * 8 + ++file;
- }
-
- rank = og_rank + 1, file = og_file - 1, index = rank * 8 + file;
- while ((rank < 8 && file >= 0) && !occupied_by(friendly_pieces, index)) {
- occupied = occupied_by(enemy_pieces, index);
- add_move(moves, from, index, .flags = occupied ? MOVE_CAPTURE : 0);
- if (occupied) {
- break;
- }
- index = ++rank * 8 + --file;
+ bitboard_t attacks = get_bishop_attacks(from, all_occupied) & ~friendly_pieces;
+ while (attacks) {
+ int to = __builtin_ctzll(attacks);
+ attacks &= attacks - 1;
+ add_move(moves, from, to, .flags = ((enemy_pieces >> to) & 1) ? MOVE_CAPTURE : 0);
}
}
}