diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2026-05-26 14:07:15 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2026-05-26 14:07:15 +0530 |
| commit | 7e021a821b49306eaa8b0688e4b91d2db25d4878 (patch) | |
| tree | 83f2848245236f079fae5a6f790f96101c6f769c /src/search/bishop_moves.c | |
| parent | c8d8d1ddf9ff8d7900d41d885cdbf177f40f0cd1 (diff) | |
rook moves
Diffstat (limited to 'src/search/bishop_moves.c')
| -rw-r--r-- | src/search/bishop_moves.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/search/bishop_moves.c b/src/search/bishop_moves.c new file mode 100644 index 0000000..10b46e5 --- /dev/null +++ b/src/search/bishop_moves.c @@ -0,0 +1,63 @@ +#include "search.h" + +void get_bishop_moves(moves_t* moves, position_t position) { + assert_valid_position(position); + + bitboard_t friendly_rooks; + bitboard_t friendly_pieces; + bitboard_t enemy_pieces; + if (position.turn == WHITE_TURN) { + friendly_pieces = whites(position); + enemy_pieces = blacks(position); + friendly_rooks = position.bitboards[WHITE_ROOK]; + } else { + friendly_pieces = blacks(position); + enemy_pieces = whites(position); + friendly_rooks = position.bitboards[BLACK_ROOK]; + } + + while (friendly_rooks) { + int from = __builtin_ctzll(friendly_rooks); + friendly_rooks &= friendly_rooks - 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; + + + while ((rank < 8 && file < 8) && !occupied_by(friendly_pieces, index)) { + add_move(moves, from, index); + if (occupied_by(enemy_pieces, index)) { + 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)) { + add_move(moves, from, index); + if (occupied_by(enemy_pieces, index)) { + 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)) { + add_move(moves, from, index); + if (occupied_by(enemy_pieces, index)) { + 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)) { + add_move(moves, from, index); + if (occupied_by(enemy_pieces, index)) { + break; + } + index = ++rank * 8 + --file; + } + } +} |
