finish fitting move_t in 16 bits

This commit is contained in:
2024-07-01 13:56:13 +02:00
parent 58c985f52f
commit a2451d79db
2 changed files with 26 additions and 22 deletions

View File

@@ -212,12 +212,9 @@ static inline __unused move_t *gen_pseudo_king(move_t *moves, square_t from,
* - castling, if king is in check
* - castling, if king passes an enemy-controlled square (not final square).
* When immediately known, a few move flags are also applied in these cases:
* - castling: M_CASTLE_{K,Q}
* - capture (excl. en-passant): M_CAPTURE
* - castling: M_CASTLE
* - en-passant: M_EN_PASSANT
* - pawn double push: M_DPUSH
* - promotion: M_PROMOTION
* - promotion and capture
*
* TODO: move code to specific functions (especially castling, pawn push/capture)
*
@@ -281,6 +278,8 @@ static inline __unused move_t *moves_gen_flags(move_t *moves, square_t from, bit
*
* Generate (at address @moves) all promotion (Q/R/B/N) moves on @to for
* pawn @from.
* Actual promoted piece type is encoded as piece - 2, i.e. N = 0, B = 1,
* R = 2, Q = 3.
*
* @Return: New @moves.
*/
@@ -327,7 +326,6 @@ static inline move_t *moves_gen(move_t *moves, square_t from, bitboard_t to_bb)
* - castling: M_CASTLE_{K,Q}
* - capture (excl. en-passant): M_CAPTURE
* - en-passant: M_EN_PASSANT
* - pawn double push: M_DPUSH
* - promotion: M_PROMOTION
* - promotion and capture
*

View File

@@ -19,45 +19,45 @@
#include "board.h"
/* move structure:
* 1 1 1 1 1
* 8 5 4 2 1 6 5 0
* FFFF ppp tttttt ffffff
* 11 11 1
* 54 32 1 6 5 0
* FF pp tttttt ffffff
*
* bits len off range type mask get desc
* ffffff 6 0 0-5 square_t 077 &077 from
* tttttt 6 6 6-11 square_t 07700 (>>6) &077 to
* ppp 3 12 12-14 piece_type_t 070000 (>>12) &07 promoted
* FFF 3 15 15-17 move_flags_t 0700000 (>>15) &07 flags
* pp 2 12 12-13 piece_type_t 030000 (>>12) &03 promoted
* FF 2 14 14-15 move_flags_t 0140000 (>>14) &03 flags
*/
typedef u32 move_t;
typedef u16 move_t;
enum {
M_OFF_FROM = 0,
M_OFF_TO = 6,
M_OFF_PROMOTED = 12,
M_OFF_FLAGS = 15
M_OFF_FLAGS = 14
};
typedef enum {
M_PROMOTION = 070000,
M_FLAGS_MASK = 0700000,
M_ENPASSANT = (1 << M_OFF_FLAGS),
M_CASTLE = (2 << M_OFF_FLAGS), /* maybe only one ? */
// M_CHECK = (3 << M_OFF_FLAGS) /* maybe unknown/useless ? */
M_PROMOTED_MASK = 0030000,
M_FLAGS_MASK = 0140000,
M_ENPASSANT = 040000, /* 1 << M_OFF_FLAGS */
M_CASTLE = 0100000, /* 2 << M_OFF_FLAGS */
M_PROMOTION = 0140000, /* 3 << M_OFF_FLAGS */
} move_flags_t;
/* special move_t values */
#define MOVE_NULL 0 /* hack: from = to = A1 */
#define MOVE_NONE 07777 /* hack: from = to = H8 */
// #define MOVE_NO_MOVE 01010 /* hack: from = to = A2 */
#define move_set_flags(move, flags) ((move) | (flags))
#define move_flags(move) ((move) & M_FLAGS_MASK)
#define is_promotion(m) ((m) & M_PROMOTION)
#define is_promotion(m) (move_flags(m) == M_PROMOTION)
#define is_enpassant(m) (move_flags(m) == M_ENPASSANT)
#define is_castle(m) (move_flags(m) == M_CASTLE)
#define is_check(m) (move_flags(m) == M_CHECK)
// #define is_check(m) (move_flags(m) == M_CHECK)
#define MOVES_MAX 256
@@ -76,9 +76,14 @@ static inline square_t move_to(move_t move)
return (move >> M_OFF_TO) & 077;
}
static inline square_t move_fromto(move_t move)
{
return move & 07777;
}
static inline piece_type_t move_promoted(move_t move)
{
return (move >> M_OFF_PROMOTED) & 07;
return ((move >> M_OFF_PROMOTED) & 03) + KNIGHT;
}
/*
@@ -114,7 +119,8 @@ 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,
piece_type_t promoted)
{
return move_make(from, to) | (promoted << M_OFF_PROMOTED);
return move_make_flags(from, to, M_PROMOTION) |
((promoted - KNIGHT) << M_OFF_PROMOTED);
}
/*