From b4cc87815bf9906fd0946aee0272219dd3ecc9e7 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Mon, 18 Mar 2024 10:12:35 +0100 Subject: [PATCH] movegen: separate all captures (easier later handling) --- src/move-gen.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/move-gen.c b/src/move-gen.c index d6cd16c..22174e6 100644 --- a/src/move-gen.c +++ b/src/move-gen.c @@ -189,40 +189,58 @@ int pos_gen_pseudomoves(pos_t *pos) /* king - MUST BE FIRST ! */ from = pos->king[us]; movebits = bb_king_moves(not_my_pieces, from); - bit_for_each64(to, tmp1, movebits) { + bit_for_each64(to, tmp1, movebits & empty) { moves[nmoves++] = move_make(from, to); } + bit_for_each64(to, tmp1, movebits & enemy_pieces) { + moves[nmoves++] = move_make_capture(from, to); + } + if (popcount64(pos->checkers) > 1) /* double check, we stop here */ return (pos->moves.nmoves = nmoves); /* sliding pieces */ - bit_for_each64(from, tmp1, pos->bb[us][BISHOP]) { + bit_for_each64(from, tmp1, pos->bb[us][BISHOP] | pos->bb[us][QUEEN]) { movebits = hyperbola_bishop_moves(occ, from) & not_my_pieces; - bit_for_each64(to, tmp2, movebits) { + bit_for_each64(to, tmp2, movebits & empty) { moves[nmoves++] = move_make(from, to); } + bit_for_each64(to, tmp2, movebits & enemy_pieces) { + moves[nmoves++] = move_make_capture(from, to); + } } - bit_for_each64(from, tmp1, pos->bb[us][ROOK]) { + bit_for_each64(from, tmp1, pos->bb[us][ROOK] | pos->bb[us][QUEEN]) { // printf("rook=%d/%s\n", from, sq_to_string(from)); movebits = hyperbola_rook_moves(occ, from) & not_my_pieces; - bit_for_each64(to, tmp2, movebits) { + bit_for_each64(to, tmp2, movebits & empty) { moves[nmoves++] = move_make(from, to); } + bit_for_each64(to, tmp2, movebits & enemy_pieces) { + moves[nmoves++] = move_make_capture(from, to); + } } /* TODO: remove this one, after movegen is validated */ - bit_for_each64(from, tmp1, pos->bb[us][QUEEN]) { - movebits = hyperbola_queen_moves(occ, from) & not_my_pieces; - bit_for_each64(to, tmp2, movebits) { - moves[nmoves++] = move_make(from, to); - } - } + /* + * bit_for_each64(from, tmp1, pos->bb[us][QUEEN]) { + * movebits = hyperbola_queen_moves(occ, from) & not_my_pieces; + * bit_for_each64(to, tmp2, movebits & empty) { + * moves[nmoves++] = move_make(from, to); + * } + * bit_for_each64(to, tmp2, movebits & enemy_pieces) { + * moves[nmoves++] = move_make_capture(from, to); + * } + * } + */ /* knight */ bit_for_each64(from, tmp1, pos->bb[us][KNIGHT]) { movebits = bb_knight_moves(not_my_pieces, from); - bit_for_each64(to, tmp2, movebits) { + bit_for_each64(to, tmp2, movebits & empty) { moves[nmoves++] = move_make(from, to); } + bit_for_each64(to, tmp2, movebits & enemy_pieces) { + moves[nmoves++] = move_make_capture(from, to); + } } /* pawn: relative rank and files */