diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 11 | ||||
| -rw-r--r-- | src/search.c | 1 | ||||
| -rw-r--r-- | src/search.h | 13 | ||||
| -rw-r--r-- | src/search/bishop_moves.c | 47 | ||||
| -rw-r--r-- | src/search/queen_moves.c | 21 | ||||
| -rw-r--r-- | src/search/rook_moves.c | 47 |
6 files changed, 99 insertions, 41 deletions
@@ -7,9 +7,9 @@ int main() { position_t position = position_starting(); position.bitboards[WHITE_KING] = 16ULL; -position.bitboards[WHITE_QUEEN] = 8ULL; +position.bitboards[WHITE_QUEEN] = 268435456ULL; position.bitboards[WHITE_ROOK] = 16777344ULL; -position.bitboards[WHITE_BISHOP] = 36ULL; +position.bitboards[WHITE_BISHOP] = 67108896ULL; position.bitboards[WHITE_KNIGHT] = 66ULL; position.bitboards[WHITE_PAWN] = 65280ULL; position.bitboards[BLACK_KING] = 1152921504606846976ULL; @@ -19,11 +19,16 @@ position.bitboards[BLACK_BISHOP] = 2594073385365405696ULL; position.bitboards[BLACK_KNIGHT] = 4611687117939015680ULL; position.bitboards[BLACK_PAWN] = 71776119061217280ULL; - get_rook_moves(&moves, position); + get_queen_moves(&moves, position); + + bitboard_t b = 0; for (int i = 0; i < moves.length; i++) { + b |= (bitboard_t)1 << moves.moves[i].to; printf("%d %d | ", (moves.moves[i].from), (moves.moves[i].to)); } + + print_bitboard(b); return 0; } diff --git a/src/search.c b/src/search.c index 03b5eb5..e389087 100644 --- a/src/search.c +++ b/src/search.c @@ -4,3 +4,4 @@ #include "search/pawn_moves.c" #include "search/rook_moves.c" #include "search/bishop_moves.c" +#include "search/queen_moves.c" diff --git a/src/search.h b/src/search.h index 14f876f..5648e99 100644 --- a/src/search.h +++ b/src/search.h @@ -29,4 +29,17 @@ void get_rook_moves(moves_t* moves, position_t position); void get_bishop_moves(moves_t* moves, position_t position); void get_queen_moves(moves_t* moves, position_t position); +void __forloop_rook_moves_gen( + moves_t* moves, + bitboard_t friendly_type, + bitboard_t friendly_pieces, + bitboard_t enemy_pieces +); +void __forloop_bishop_moves_gen( + moves_t* moves, + bitboard_t friendly_type, + bitboard_t friendly_pieces, + bitboard_t enemy_pieces +); + #endif // !SEARCH_H diff --git a/src/search/bishop_moves.c b/src/search/bishop_moves.c index 10b46e5..29fe3a6 100644 --- a/src/search/bishop_moves.c +++ b/src/search/bishop_moves.c @@ -1,24 +1,14 @@ #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; +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] @@ -61,3 +51,22 @@ void get_bishop_moves(moves_t* moves, position_t position) { } } } + +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); +} diff --git a/src/search/queen_moves.c b/src/search/queen_moves.c new file mode 100644 index 0000000..f1e773a --- /dev/null +++ b/src/search/queen_moves.c @@ -0,0 +1,21 @@ +#include "search.h" + +void get_queen_moves(moves_t* moves, position_t position) { + assert_valid_position(position); + + bitboard_t friendly_queens; + bitboard_t friendly_pieces; + bitboard_t enemy_pieces; + if (position.turn == WHITE_TURN) { + friendly_pieces = whites(position); + enemy_pieces = blacks(position); + friendly_queens = position.bitboards[WHITE_QUEEN]; + } else { + friendly_pieces = blacks(position); + enemy_pieces = whites(position); + friendly_queens = position.bitboards[BLACK_QUEEN]; + } + + __forloop_rook_moves_gen(moves, friendly_queens, friendly_pieces, enemy_pieces); + __forloop_bishop_moves_gen(moves, friendly_queens, friendly_pieces, enemy_pieces); +} diff --git a/src/search/rook_moves.c b/src/search/rook_moves.c index 749210e..778c6a1 100644 --- a/src/search/rook_moves.c +++ b/src/search/rook_moves.c @@ -1,24 +1,14 @@ #include "search.h" -void get_rook_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; +void __forloop_rook_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] @@ -61,3 +51,22 @@ void get_rook_moves(moves_t* moves, position_t position) { } } } + +void get_rook_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]; + } + + __forloop_rook_moves_gen(moves, friendly_rooks, friendly_pieces, enemy_pieces); +} |
