diff options
Diffstat (limited to 'src/engine/moves/rook.c')
| -rw-r--r-- | src/engine/moves/rook.c | 50 |
1 files changed, 6 insertions, 44 deletions
diff --git a/src/engine/moves/rook.c b/src/engine/moves/rook.c index abbc784..0938de9 100644 --- a/src/engine/moves/rook.c +++ b/src/engine/moves/rook.c @@ -7,53 +7,15 @@ void __forloop_rook_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, index = rank * 8 + file; - - - bitboard_t occupied; - while (rank < 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, index = rank * 8 + file; - while (rank >= 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, file = og_file + 1, index = rank * 8 + file; - while (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, file = og_file - 1, index = rank * 8 + file; - while (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_rook_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); } } } |
