add move_make_promote_capture and move_make_capture

This commit is contained in:
2024-03-11 16:10:16 +01:00
parent 301ca24783
commit 890cb05296
2 changed files with 121 additions and 87 deletions

View File

@@ -19,50 +19,52 @@
#include "board.h"
/* move structure:
* 3 2 2 1 1 1 1 1 1
* 1 5 4 8 7 5 4 2 1 6 5 0
* UUUUUUU FFFFFFF ppp ccc tttttt ffffff
* 3 2 2 1 1 1 1 1 1
* 1 5 3 8 7 5 4 2 1 6 5 0
* UUUUUUUU FFFFFF ppp ccc tttttt ffffff
*
* bits range type mask get desc
* ffffff 0-5 square_t 3f &63 from
* tttttt 6-11 square_t fc0 (>>6)&63 to
* ccc 12-14 piece_type_t 7000 (>>12)&7 captured
* ppp 15-17 piece_type_t 38000 (>>15)&7 promoted
* FFFFFFF 18-24 N/A 1fc0000 N/A flags
* UUUUUUU 25-31 unused fe000000 N/A future usage ?
* bits len range type mask get desc
* ffffff 6 0-5 square_t 3f &63 from
* tttttt 6 6-11 square_t fc0 (>>6)&63 to
* ccc 3 12-14 piece_type_t 7000 (>>12)&7 captured
* ppp 3 15-17 piece_type_t 38000 (>>15)&7 promoted
* FFFFFF 6 18-23 move_flags_t fc0000 N/A flags
* UUUUUUUU 8 24-31 unused fe000000 N/A future usage ?
*/
#define move_t u32
typedef u32 move_t;
/* move flags */
#define M_FLAGS_BEG 18
#define M_HAS_FLAGS mask(M_FLAGS_BEG + 0) /* probably unused */
#define M_CAPTURE mask(M_FLAGS_BEG + 1)
#define M_EPASSANT mask(M_FLAGS_BEG + 2)
#define M_PROMOTE mask(M_FLAGS_BEG + 3)
#define M_CASTLE_K mask(M_FLAGS_BEG + 4)
#define M_CASTLE_Q mask(M_FLAGS_BEG + 5)
#define M_CHECK mask(M_FLAGS_BEG + 6) /* probably unknown/useless */
#define M_FLAGS (M_CAPTURE | M_ENPASSANT | M_PROMOTION | \
M_CASTLE_K | M_CASTLE_Q | M_CHECK)
#define M_NORMAL (~M_FLAGS)
typedef enum {
M_START = 18,
M_CAPTURE = (1 << (M_START + 0)),
M_ENPASSANT = (1 << (M_START + 1)),
M_PROMOTION = (1 << (M_START + 2)),
M_CASTLE_K = (1 << (M_START + 3)), /* maybe only one ? */
M_CASTLE_Q = (1 << (M_START + 4)), /* maybe only one ? */
M_CHECK = (1 << (M_START + 5)) /* maybe unknown/useless ? */
} move_type_t;
#define MOVES_MAX 256
static inline move_t move_make(square_t from, square_t to)
{
return (to << 6) | from;
}
typedef struct __movelist_s {
move_t move[MOVES_MAX];
int nmoves; /* total moves (fill) */
int curmove; /* current move (use) */
} movelist_t;
static inline move_t move_make_flags(square_t from, square_t to, int flags)
{
return move_make(from, to) | flags;
}
static inline move_t move_make_promote(square_t from, square_t to, piece_type_t piece)
{
return move_make(from, to) | M_PROMOTE | (piece << 15);
}
/* move flags */
//#define M_FLAGS_BEG 18
//#define M_HAS_FLAGS mask(M_FLAGS_BEG + 0) /* probably useless */
//#define M_CAPTURE mask(M_FLAGS_BEG + 0)
//#define M_EN_PASSANT mask(M_FLAGS_BEG + 1)
//#define M_PROMOTION mask(M_FLAGS_BEG + 2)
//#define M_CASTLE_K mask(M_FLAGS_BEG + 3) /* maybe only one ? */
//#define M_CASTLE_Q mask(M_FLAGS_BEG + 4) /* maybe only one ? */
//#define M_CHECK mask(M_FLAGS_BEG + 5) /* probably unknown/useless */
//#define M_FLAGS (M_CAPTURE | M_ENPASSANT | M_PROMOTION |
// M_CASTLE_K | M_CASTLE_Q | M_CHECK)
//#define M_NORMAL (~M_FLAGS)
static inline square_t move_from(move_t move)
{
@@ -73,6 +75,43 @@ static inline square_t move_to(move_t move)
return (move >> 6) & 077;
}
static inline piece_t move_promoted(move_t move)
{
return (move >> 15) & 07;
}
static inline piece_t move_captured(move_t move)
{
return (move >> 12) & 07;
}
static inline move_t move_make(square_t from, square_t to)
{
return (to << 6) | from;
}
static inline move_t move_make_flags(square_t from, square_t to, move_type_t flags)
{
return move_make(from, to) | flags;
}
static inline move_t move_make_capture(square_t from, square_t to)
{
return move_make_flags(from, to, M_CAPTURE);
}
static inline move_t move_make_promote(square_t from, square_t to,
piece_type_t promoted)
{
return move_make_flags(from, to, M_PROMOTION) | (promoted << 15);
}
static inline move_t move_make_promote_capture(square_t from, square_t to,
piece_type_t promoted)
{
return move_make_flags(from, to, M_CAPTURE | M_PROMOTION) | (promoted << 15);
}
/* moves_print flags
*/
#define M_PR_CAPT 0x01
@@ -83,12 +122,6 @@ static inline square_t move_to(move_t move)
#define M_PR_SEPARATE 0x40 /* separate captures */
#define M_PR_LONG 0x80
typedef struct __movelist_s {
move_t move[MOVES_MAX];
int nmoves; /* total moves (fill) */
int curmove; /* current move (use) */
} movelist_t;
//pool_t *moves_pool_init();
//void moves_pool_stats();