move: exclusive M_CAPTURE / M_EN_PASSANT

This commit is contained in:
2024-03-20 09:58:42 +01:00
parent ae6328ce26
commit 3a06407d5a
3 changed files with 12 additions and 13 deletions

View File

@@ -157,8 +157,8 @@ movelist_t *pos_all_legal(const pos_t *pos, movelist_t *dest)
* - castling, if king passes an enemy-controlled square (not final square). * - castling, if king passes an enemy-controlled square (not final square).
* When immediately known, a few move flags are also applied in these cases: * When immediately known, a few move flags are also applied in these cases:
* - castling: M_CASTLE_{K,Q} * - castling: M_CASTLE_{K,Q}
* - pawn capture (incl. en-passant): M_CAPTURE * - pawn capture (excl. en-passant): M_CAPTURE
* en-passant: M_EN_PASSANT * - en-passant: M_EN_PASSANT
* - pawn double push: M_DPUSH * - pawn double push: M_DPUSH
* - promotion: M_PROMOTION * - promotion: M_PROMOTION
* - promotion and capture * - promotion and capture
@@ -311,18 +311,18 @@ int pos_gen_pseudomoves(pos_t *pos)
bitboard_t rel_rank1 = bb_rel_rank(RANK_1, us); bitboard_t rel_rank1 = bb_rel_rank(RANK_1, us);
from = pos->king[us]; from = pos->king[us];
square_t from_square[2] = { E1, E8 }; /* verify king is on E1/E8 */ square_t from_square[2] = { E1, E8 }; /* verify king is on E1/E8 */
bug_on(CAN_CASTLE(pos->castle, us) && from != from_square[us]); bug_on(can_castle(pos->castle, us) && from != from_square[us]);
/* For castle, we check the opponent attacks on squares between from and to. /* For castle, we check the opponent attacks on squares between from and to.
* To square attack check will be done in gen_is_legal. * To square attack check will be done in gen_is_legal.
*/ */
if (CAN_OO(pos->castle, us)) { if (can_oo(pos->castle, us)) {
bitboard_t occmask = rel_rank1 & (FILE_Fbb | FILE_Gbb); bitboard_t occmask = rel_rank1 & (FILE_Fbb | FILE_Gbb);
if (!(occ & occmask) && if (!(occ & occmask) &&
!sq_attackers(pos, occ, from+1, them)) { /* f1/f8 */ !sq_attackers(pos, occ, from+1, them)) { /* f1/f8 */
moves[nmoves++] = move_make_flags(from, from + 2, M_CASTLE_K); moves[nmoves++] = move_make_flags(from, from + 2, M_CASTLE_K);
} }
} }
if (CAN_OOO(pos->castle, us)) { if (can_ooo(pos->castle, us)) {
bitboard_t occmask = rel_rank1 & (FILE_Bbb | FILE_Cbb | FILE_Dbb); bitboard_t occmask = rel_rank1 & (FILE_Bbb | FILE_Cbb | FILE_Dbb);
if (!(occ & occmask) && if (!(occ & occmask) &&
!sq_attackers(pos, occ, from-1, them)) { /* d1/d8 */ !sq_attackers(pos, occ, from-1, them)) { /* d1/d8 */

View File

@@ -110,7 +110,7 @@ char *move_str(char *dst, const move_t move, __unused const int flags)
sprintf(dst, "%s%s%n", sq_to_string(from), sq_to_string(to), &len); sprintf(dst, "%s%s%n", sq_to_string(from), sq_to_string(to), &len);
if (is_promotion(move)) { if (is_promotion(move)) {
piece_t promoted = move_promoted(move); piece_t promoted = (piece_t) move_promoted(move);
sprintf(dst + len, "%s", piece_to_low(promoted)); sprintf(dst + len, "%s", piece_to_low(promoted));
} }
return dst; return dst;
@@ -147,8 +147,8 @@ static int _moves_cmp_bysquare(const void *p1, const void *p2)
square_t t1 = move_to(m1); square_t t1 = move_to(m1);
square_t f2 = move_from(m2); square_t f2 = move_from(m2);
square_t t2 = move_to(m2); square_t t2 = move_to(m2);
piece_t prom1 = move_promoted(m1); piece_type_t prom1 = move_promoted(m1);
piece_t prom2 = move_promoted(m2); piece_type_t prom2 = move_promoted(m2);
if (f1 < f2) return -1; if (f1 < f2) return -1;
if (f1 > f2) return 1; if (f1 > f2) return 1;
/* f1 == f2 */ /* f1 == f2 */

View File

@@ -19,8 +19,8 @@
#include "board.h" #include "board.h"
/* move structure: /* move structure:
* 3 3 2 2 1 1 1 1 1 1 * 3 3 2 2 1 1 1 1 1 1
* 1 0 5 3 8 7 5 4 2 1 6 5 0 * 1 0 4 3 8 7 5 4 2 1 6 5 0
* S UUUUUUU FFFFFF ccc ppp tttttt ffffff * S UUUUUUU FFFFFF ccc ppp tttttt ffffff
* *
* bits len off range type mask get desc * bits len off range type mask get desc
@@ -84,7 +84,7 @@ static inline square_t move_to(move_t move)
return (move >> M_OFF_TO) & 077; return (move >> M_OFF_TO) & 077;
} }
static inline piece_t move_promoted(move_t move) static inline piece_type_t move_promoted(move_t move)
{ {
return (move >> M_OFF_PROMOTED) & 07; return (move >> M_OFF_PROMOTED) & 07;
} }
@@ -94,7 +94,6 @@ static inline piece_type_t move_captured(move_t move)
return (move >> M_OFF_CAPTURED) & 07; return (move >> M_OFF_CAPTURED) & 07;
} }
static inline move_t move_make(square_t from, square_t to) static inline move_t move_make(square_t from, square_t to)
{ {
return (to << M_OFF_TO) | from; return (to << M_OFF_TO) | from;
@@ -112,7 +111,7 @@ static inline move_t move_make_capture(square_t from, square_t to)
static inline move_t move_make_enpassant(square_t from, square_t to) static inline move_t move_make_enpassant(square_t from, square_t to)
{ {
return move_make_flags(from, to, M_CAPTURE | M_ENPASSANT); return move_make_flags(from, to, M_ENPASSANT);
} }
static inline move_t move_make_promote(square_t from, square_t to, static inline move_t move_make_promote(square_t from, square_t to,