From 2c2a70b69869f149c0407a62f1bf4c39899027a7 Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Wed, 27 May 2026 18:02:44 +0530 Subject: restructing --- src/engine/moves/bishop.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/engine/moves/bishop.c (limited to 'src/engine/moves/bishop.c') diff --git a/src/engine/moves/bishop.c b/src/engine/moves/bishop.c new file mode 100644 index 0000000..52b90b3 --- /dev/null +++ b/src/engine/moves/bishop.c @@ -0,0 +1,77 @@ +#include "../moves.h" + +void __forloop_bishop_moves_gen( + moves_t* moves, + bitboard_t friendly_type, + bitboard_t friendly_pieces, + bitboard_t 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; + + + 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; + } + } +} + +void get_bishop_moves(moves_t* moves, position_t position) { + assert_valid_position(position); + + bitboard_t friendly_bishops; + bitboard_t friendly_pieces; + bitboard_t enemy_pieces; + if (position.turn == WHITE_TURN) { + friendly_pieces = whites(position); + enemy_pieces = blacks(position); + friendly_bishops = position.bitboards[WHITE_BISHOP]; + } else { + friendly_pieces = blacks(position); + enemy_pieces = whites(position); + friendly_bishops = position.bitboards[BLACK_BISHOP]; + } + + __forloop_bishop_moves_gen( + moves, + friendly_bishops, + friendly_pieces, + enemy_pieces + ); +} -- cgit v1.2.3