Add all legal pawn promotions

Initially, I only included Queen promos, but this is an issue
with perft testing, since the community counts all legal promotions
as moves. Debugging will be really difficult if I don't include this
now.
This commit is contained in:
2025-08-19 15:29:56 -04:00
parent 1b62d13acd
commit 5b4a901f8d

View File

@@ -220,6 +220,9 @@ void gen_white_pawn_push_promotions(const struct Board *board, struct Move *out,
int to = pop_lsb_index(&promos); int to = pop_lsb_index(&promos);
int from = to - 8; int from = to - 8;
push_move(out, count, from, to, P, Q, MF_PROMO); push_move(out, count, from, to, P, Q, MF_PROMO);
push_move(out, count, from, to, P, R, MF_PROMO);
push_move(out, count, from, to, P, B, MF_PROMO);
push_move(out, count, from, to, P, N, MF_PROMO);
} }
} }
@@ -235,6 +238,9 @@ void gen_black_pawn_push_promotions(const struct Board *board, struct Move *out,
int to = pop_lsb_index(&promos); int to = pop_lsb_index(&promos);
int from = to + 8; int from = to + 8;
push_move(out, count, from, to, p, q, MF_PROMO); push_move(out, count, from, to, p, q, MF_PROMO);
push_move(out, count, from, to, p, r, MF_PROMO);
push_move(out, count, from, to, p, b, MF_PROMO);
push_move(out, count, from, to, p, n, MF_PROMO);
} }
} }
@@ -245,14 +251,20 @@ void gen_white_pawn_capture_promotions(const struct Board *board, struct Move *o
while (left) { while (left) {
int to = pop_lsb_index(&left); int to = pop_lsb_index(&left);
int from = to - 7; int from = to - 7;
push_move(out, count,from, to, P, Q, MF_CAPTURE | MF_PROMO); push_move(out, count, from, to, P, Q, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, P, R, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, P, B, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, P, N, MF_CAPTURE | MF_PROMO);
} }
// right capture: +9, mask off file H // right capture: +9, mask off file H
uint64_t right = ((board->pieces[P] & ~FILE_H) << 9) & opp & RANK_8; uint64_t right = ((board->pieces[P] & ~FILE_H) << 9) & opp & RANK_8;
while (right) { while (right) {
int to = pop_lsb_index(&right); int to = pop_lsb_index(&right);
int from = to - 9; int from = to - 9;
push_move(out, count,from, to, P, Q, MF_CAPTURE | MF_PROMO); push_move(out, count, from, to, P, Q, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, P, R, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, P, B, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, P, N, MF_CAPTURE | MF_PROMO);
} }
} }
@@ -263,14 +275,20 @@ void gen_black_pawn_capture_promotions(const struct Board *board, struct Move *o
while (left) { while (left) {
int to = pop_lsb_index(&left); int to = pop_lsb_index(&left);
int from = to + 7; int from = to + 7;
push_move(out, count,from, to, p, q, MF_CAPTURE | MF_PROMO); push_move(out, count, from, to, p, q, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, p, r, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, p, b, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, p, n, MF_CAPTURE | MF_PROMO);
} }
// “right” is -9 (mask off file A) // “right” is -9 (mask off file A)
uint64_t right = ((board->pieces[p] & ~FILE_A) >> 9) & opp & RANK_1; uint64_t right = ((board->pieces[p] & ~FILE_A) >> 9) & opp & RANK_1;
while (right) { while (right) {
int to = pop_lsb_index(&right); int to = pop_lsb_index(&right);
int from = to + 9; int from = to + 9;
push_move(out, count,from, to, p, q, MF_CAPTURE | MF_PROMO); push_move(out, count, from, to, p, q, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, p, r, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, p, b, MF_CAPTURE | MF_PROMO);
push_move(out, count, from, to, p, n, MF_CAPTURE | MF_PROMO);
} }
} }