clean move_t: Remove capture/dpush/promotion flags, captured piece

This commit is contained in:
2024-06-12 07:45:22 +02:00
parent 49b678e3ce
commit ec2d2291d4
4 changed files with 45 additions and 37 deletions

View File

@@ -100,7 +100,7 @@ pos_t *move_do(pos_t *pos, const move_t move, state_t *state)
pos->castle = clr_castle(pos->castle, us); pos->castle = clr_castle(pos->castle, us);
} else if (ptype == PAWN) { /* pawn non capture or e.p. */ } else if (ptype == PAWN) { /* pawn non capture or e.p. */
pos->clock_50 = 0; pos->clock_50 = 0;
if (is_dpush(move)) { /* if pawn double push, set e.p. */ if (from + up + up == to) { /* if pawn double push, set e.p. */
square_t ep = from + up;; square_t ep = from + up;;
if (bb_pawn_attacks[us][ep] & pos->bb[them][PAWN]) { if (bb_pawn_attacks[us][ep] & pos->bb[them][PAWN]) {
pos->en_passant = ep; pos->en_passant = ep;
@@ -265,7 +265,7 @@ pos_t *move_do_alt(pos_t *pos, const move_t move) //, state_t *state)
pos->castle = clr_castle(pos->castle, us); pos->castle = clr_castle(pos->castle, us);
} else if (ptype == PAWN) { /* pawn non capture or e.p. */ } else if (ptype == PAWN) { /* pawn non capture or e.p. */
pos->clock_50 = 0; pos->clock_50 = 0;
if (is_dpush(move)) { /* if pawn double push, set e.p. */ if (from + up + up == to) { /* if pawn double push, set e.p. */
square_t ep = from + up;; square_t ep = from + up;;
if (bb_pawn_attacks[us][ep] & pos->bb[them][PAWN]) { if (bb_pawn_attacks[us][ep] & pos->bb[them][PAWN]) {
pos->en_passant = ep; pos->en_passant = ep;

View File

@@ -460,7 +460,8 @@ movelist_t *pos_gen_pseudo(pos_t *pos, movelist_t *movelist)
while(to_bb) { while(to_bb) {
to = bb_next(&to_bb); to = bb_next(&to_bb);
from = to - shift - shift; from = to - shift - shift;
*moves++ = move_make_flags(from, to, M_DPUSH); //*moves++ = move_make_flags(from, to, M_DPUSH);
*moves++ = move_make(from, to);
} }
/* pawn: captures */ /* pawn: captures */

View File

@@ -89,7 +89,7 @@
*/ */
/** /**
* move_str() - get a move string * move_to_str() - get a move string
* @dst: destination memory * @dst: destination memory
* @move: move * @move: move
* @flags: moves selection and display options. * @flags: moves selection and display options.
@@ -102,7 +102,7 @@
* M_PR_NL: print a newline after move * M_PR_NL: print a newline after move
* M_PR_EVAL: print move eval * M_PR_EVAL: print move eval
*/ */
char *move_str(char *dst, const move_t move, __unused const int flags) char *move_to_str(char *dst, const move_t move, __unused const int flags)
{ {
square_t from = move_from(move); square_t from = move_from(move);
square_t to = move_to(move); square_t to = move_to(move);
@@ -116,7 +116,6 @@ char *move_str(char *dst, const move_t move, __unused const int flags)
return dst; return dst;
} }
/** /**
* moves_print() - print movelist moves. * moves_print() - print movelist moves.
* @moves: &movelist_t moves list * @moves: &movelist_t moves list
@@ -135,7 +134,7 @@ void moves_print(movelist_t *moves, __unused int flags)
char str[16]; char str[16];
//printf("%2d:", moves->nmoves); //printf("%2d:", moves->nmoves);
for (int m = 0; m < moves->nmoves; ++m) for (int m = 0; m < moves->nmoves; ++m)
printf("%s ", move_str(str, moves->move[m], flags)); printf("%s ", move_to_str(str, moves->move[m], flags));
printf("\n"); printf("\n");
} }

View File

@@ -42,30 +42,30 @@ enum {
M_OFF_FROM = 0, M_OFF_FROM = 0,
M_OFF_TO = 6, M_OFF_TO = 6,
M_OFF_PROMOTED = 12, M_OFF_PROMOTED = 12,
M_OFF_CAPTURED = 15, // M_OFF_CAPTURED = 15,
M_OFF_FLAGS = 18 M_OFF_FLAGS = 15
}; };
typedef enum { typedef enum {
M_CAPTURE = BIT(M_OFF_FLAGS + 0), M_PROMOTION = 070000,
M_ENPASSANT = BIT(M_OFF_FLAGS + 1), // M_CAPTURE = BIT(M_OFF_FLAGS + 0),
M_PROMOTION = BIT(M_OFF_FLAGS + 2), M_ENPASSANT = BIT(M_OFF_FLAGS + 0),
M_CASTLE_K = BIT(M_OFF_FLAGS + 3), /* maybe only one ? */ M_CASTLE_K = BIT(M_OFF_FLAGS + 1), /* maybe only one ? */
M_CASTLE_Q = BIT(M_OFF_FLAGS + 5), /* maybe only one ? */ M_CASTLE_Q = BIT(M_OFF_FLAGS + 2), /* maybe only one ? */
M_CHECK = BIT(M_OFF_FLAGS + 6), /* maybe unknown/useless ? */ M_CHECK = BIT(M_OFF_FLAGS + 3), /* maybe unknown/useless ? */
M_DPUSH = BIT(M_OFF_FLAGS + 7) /* pawn double push */ // M_DPUSH = BIT(M_OFF_FLAGS + 7) /* pawn double push */
} move_flags_t; } move_flags_t;
#define move_set_flags(move, flags) ((move) | (flags)) #define move_set_flags(move, flags) ((move) | (flags))
#define is_capture(m) ((m) & M_CAPTURE) //#define is_capture(m) ((m) & M_CAPTURE)
#define is_enpassant(m) ((m) & M_ENPASSANT) #define is_enpassant(m) ((m) & M_ENPASSANT)
#define is_promotion(m) ((m) & M_PROMOTION) #define is_promotion(m) ((m) & M_PROMOTION)
#define is_castle(m) ((m) & (M_CASTLE_K | M_CASTLE_Q)) #define is_castle(m) ((m) & (M_CASTLE_K | M_CASTLE_Q))
#define is_castle_K(m) ((m) & M_CASTLE_K) #define is_castle_K(m) ((m) & M_CASTLE_K)
#define is_castle_Q(m) ((m) & M_CASTLE_Q) #define is_castle_Q(m) ((m) & M_CASTLE_Q)
#define is_check(m) ((m) & M_CHECK) #define is_check(m) ((m) & M_CHECK)
#define is_dpush(m) ((m) & M_DPUSH) //#define is_dpush(m) ((m) & M_DPUSH)
#define MOVES_MAX 256 #define MOVES_MAX 256
@@ -89,10 +89,12 @@ static inline piece_type_t move_promoted(move_t move)
return (move >> M_OFF_PROMOTED) & 07; return (move >> M_OFF_PROMOTED) & 07;
} }
static inline piece_type_t move_captured(move_t move) /*
{ * 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)
{ {
@@ -105,10 +107,12 @@ static inline move_t move_make_flags(square_t from, square_t to, move_flags_t fl
//move_set_flags(move_make(from, to), flags); //move_set_flags(move_make(from, to), flags);
} }
static inline move_t move_make_capture(square_t from, square_t to) /*
{ * static inline move_t move_make_capture(square_t from, square_t to)
return move_make_flags(from, to, M_CAPTURE); * {
} * return move_make_flags(from, to, M_CAPTURE);
* }
*/
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)
{ {
@@ -118,19 +122,23 @@ static inline move_t move_make_enpassant(square_t from, square_t to)
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,
piece_type_t promoted) piece_type_t promoted)
{ {
return move_make_flags(from, to, M_PROMOTION) | (promoted << M_OFF_PROMOTED); return move_make(from, to) | (promoted << M_OFF_PROMOTED);
} }
static inline move_t move_make_promote_capture(square_t from, square_t to, /*
piece_type_t promoted) * static inline move_t move_make_promote_capture(square_t from, square_t to,
{ * piece_type_t promoted)
return move_make_promote(from, to, promoted) | M_CAPTURE; * {
} * return move_make_promote(from, to, promoted) | M_CAPTURE;
* }
*/
static inline move_t move_set_captured(move_t move, piece_type_t captured) /*
{ * static inline move_t move_set_captured(move_t move, piece_type_t captured)
return move | (captured << M_OFF_CAPTURED); * {
} * return move | (captured << M_OFF_CAPTURED);
* }
*/
/* moves_print flags /* moves_print flags
*/ */
@@ -144,7 +152,7 @@ static inline move_t move_set_captured(move_t move, piece_type_t captured)
#define M_PR_LONG 0x80 #define M_PR_LONG 0x80
//int move_print(int movenum, move_t *move, move_flags_t flags); //int move_print(int movenum, move_t *move, move_flags_t flags);
char *move_str(char *dst, const move_t move, __unused const int flags); char *move_to_str(char *dst, const move_t move, __unused const int flags);
void moves_print(movelist_t *moves, int flags); void moves_print(movelist_t *moves, int flags);
void move_sort_by_sq(movelist_t *moves); void move_sort_by_sq(movelist_t *moves);