From 5a25eba8f64598afad56a17f59ab99cf38dc6a8c Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 17 Aug 2025 12:17:51 -0400 Subject: [PATCH] Add move_gen function --- engine/include/bitboard.h | 10 +++++++++- engine/src/bitboard.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/engine/include/bitboard.h b/engine/include/bitboard.h index 3d940a8..acd9318 100644 --- a/engine/include/bitboard.h +++ b/engine/include/bitboard.h @@ -106,4 +106,12 @@ void create_knight_attack_cache(); void create_pawn_attack_cache(); void create_king_attack_cache(); void print_board(); -int gen_pseudo_moves(struct Board *b, struct Move *out, bool captures_only); \ No newline at end of file +void gen_white_pawn_quiet_pushes(const struct Board *board, struct Move *moves, int *count); +void gen_black_pawn_quiet_pushes(const struct Board *board, struct Move *moves, int *count); +void gen_white_pawn_push_promotions(const struct Board *board, struct Move *moves, int *count); +void gen_black_pawn_push_promotions(const struct Board *board, struct Move *moves, int *count); +void gen_white_pawn_captures(const struct Board *board, struct Move *moves, int *count); +void gen_black_pawn_captures(const struct Board *board, struct Move *moves, int *count); +void gen_white_pawn_capture_promotions(const struct Board *board, struct Move *moves, int *count); +void gen_black_pawn_capture_promotions(const struct Board *board, struct Move *moves, int *count); +int gen_pseudo_moves(const struct Board *board, struct Move *out, bool captures_only); \ No newline at end of file diff --git a/engine/src/bitboard.c b/engine/src/bitboard.c index a69f3bb..3583eb4 100644 --- a/engine/src/bitboard.c +++ b/engine/src/bitboard.c @@ -458,7 +458,7 @@ void gen_queen_moves(const struct Board *board, struct Move *out, int *count, bo } } -void gen_king_moves(struct Board *board, struct Move *out, int *count, bool captures_only) { +void gen_king_moves(const struct Board *board, struct Move *out, int *count, bool captures_only) { enum Color side = board->side_to_move; uint64_t own = board->occ[side]; uint64_t opp = board->occ[side ^ 1]; @@ -502,6 +502,35 @@ void gen_king_moves(struct Board *board, struct Move *out, int *count, bool capt } } +int gen_pseudo_moves(const struct Board *board, struct Move *moves, bool captures_only) { + int count = 0; + + if (board->side_to_move == WHITE) { + if (!captures_only) { + gen_white_pawn_quiet_pushes(board, moves, &count); + gen_white_pawn_push_promotions(board, moves, &count); + } + gen_white_pawn_captures(board, moves, &count); + gen_white_pawn_capture_promotions(board, moves, &count); + } else { + if (!captures_only) { + gen_black_pawn_quiet_pushes(board, moves, &count); + gen_black_pawn_push_promotions(board, moves, &count); + } + gen_black_pawn_captures(board, moves, &count); + gen_black_pawn_capture_promotions(board, moves, &count); + } + + gen_knight_moves(board, moves, &count, captures_only); + gen_king_moves(board, moves, &count, captures_only); + gen_rook_moves(board, moves, &count, captures_only); + gen_bishop_moves(board, moves, &count, captures_only); + gen_queen_moves(board, moves, &count, captures_only); + + return count; +} + + void print_board(const struct Board *board) { const char PIECE_CH[12] = { 'P','N','B','R','Q','K',