convert piece_t, square_t etc. to u8 (no more typed enum. See C23 ?).
This commit is contained in:
18
MEMO.org
18
MEMO.org
@@ -1,2 +1,18 @@
|
||||
** Some current ideas
|
||||
- hmmm. Empty brain.
|
||||
- Test popbit/square_of with intrinsincs, something like :
|
||||
bitboard_t popbit64(bitboard_t *bb)
|
||||
{
|
||||
bitboard_t first = _blsi_u64(*bb);
|
||||
*bb ^= lsb;
|
||||
return first;
|
||||
}
|
||||
|
||||
square_t square_of(bitboard_t bb) {
|
||||
return _tzcnt_u64(bb);
|
||||
}
|
||||
|
||||
loop:
|
||||
while (bb) {
|
||||
bitboard_t first = popbit(bb);
|
||||
square_t sq = square_of(first);
|
||||
}
|
||||
|
@@ -217,7 +217,7 @@ void bb_print(const char *title, const bitboard_t bitboard)
|
||||
//char c = p? p: 'X';
|
||||
if (title)
|
||||
printf("%s\n", title);
|
||||
for (rank_t r = RANK_8; r >= RANK_1; --r) {
|
||||
for (rank_t r = RANK_8 + 1; r --> RANK_1;) { /* "downto"" op." */
|
||||
printf("%d ", r + 1);
|
||||
for (file_t f = FILE_A; f <= FILE_H; ++f) {
|
||||
printf(" %c", bitboard & bb_sq[sq_make(f, r)] ? 'X': '.');
|
||||
@@ -252,7 +252,7 @@ void bb_print_multi(const char *title, int n, ...)
|
||||
if (title)
|
||||
printf("%s\n", title);
|
||||
|
||||
for (rank_t r = RANK_8; r >= RANK_1; --r) {
|
||||
for (rank_t r = RANK_8 + 1; r --> RANK_1;) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
printf("%d ", r + 1);
|
||||
for (file_t f = FILE_A; f <= FILE_H; ++f) {
|
||||
|
@@ -115,7 +115,7 @@ void board_print_mask(const piece_t *board, const bitboard_t mask)
|
||||
*/
|
||||
void board_print_raw(const piece_t *board, const int type)
|
||||
{
|
||||
for (rank_t r = RANK_8; r >= RANK_1; --r) {
|
||||
for (rank_t r = RANK_8 + 1; r --> RANK_1;) {
|
||||
for (file_t f = FILE_A; f <= FILE_H; ++f) {
|
||||
piece_t p = board[sq_make(f, r)];
|
||||
if (type) {
|
||||
|
@@ -56,8 +56,8 @@ static __always_inline rank_t sq_rank(square_t square)
|
||||
return square >> 3;
|
||||
}
|
||||
|
||||
#define sq_ok(sq) ((sq) >= A1 && (sq) <= H8)
|
||||
#define sq_coord_ok(c) ((c) >= 0 && (c) < 8)
|
||||
#define sq_ok(sq) ((sq) <= H8)
|
||||
#define sq_coord_ok(c) ((c) < 8)
|
||||
|
||||
/**
|
||||
* sq_dist() - Chebyshev (king) distance between two squares (macro).
|
||||
|
@@ -99,8 +99,8 @@ typedef s16 eval_t;
|
||||
* To simplify cross-dependancies, all important enum are moved here.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
_SSQUARE_ = -1, /* force signed enum */
|
||||
enum {
|
||||
//_SSQUARE_ = -1, /* force signed enum */
|
||||
A1 = 0, B1, C1, D1, E1, F1, G1, H1,
|
||||
A2, B2, C2, D2, E2, F2, G2, H2,
|
||||
A3, B3, C3, D3, E3, F3, G3, H3,
|
||||
@@ -111,21 +111,24 @@ typedef enum {
|
||||
A8, B8, C8, D8, E8, F8, G8, H8,
|
||||
SQUARE_MAX = 64,
|
||||
SQUARE_NONE = 64
|
||||
} square_t;
|
||||
};
|
||||
typedef u8 square_t;
|
||||
|
||||
typedef enum {
|
||||
_SFILE_ = -1, /* force signed enum */
|
||||
enum {
|
||||
//_SFILE_ = -1, /* force signed enum */
|
||||
FILE_A = 0, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H,
|
||||
FILE_MAX,
|
||||
} file_t;
|
||||
};
|
||||
typedef u8 file_t;
|
||||
|
||||
typedef enum {
|
||||
_SRANK_ = -1, /* force signed enum */
|
||||
enum {
|
||||
//_SRANK_ = -1, /* force signed enum */
|
||||
RANK_1 = 0, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8,
|
||||
RANK_MAX,
|
||||
} rank_t;
|
||||
};
|
||||
typedef u8 rank_t;
|
||||
|
||||
typedef enum {
|
||||
enum {
|
||||
NORTH = 8,
|
||||
EAST = 1,
|
||||
SOUTH = -NORTH,
|
||||
@@ -135,7 +138,8 @@ typedef enum {
|
||||
SOUTH_EAST = (SOUTH + EAST),
|
||||
SOUTH_WEST = (SOUTH + WEST),
|
||||
NORTH_WEST = (NORTH + WEST),
|
||||
} dir_t;
|
||||
};
|
||||
typedef u8 dir_t;
|
||||
|
||||
/* define diff for relative squares */
|
||||
#define sq_up(c) ((c) == WHITE ? NORTH: SOUTH)
|
||||
|
@@ -292,7 +292,7 @@ char *pos2fen(const pos_t *pos, char *fen)
|
||||
|
||||
/* 1) position
|
||||
*/
|
||||
for (rank_t r = RANK_8; r >= RANK_1; --r) {
|
||||
for (rank_t r = RANK_8 + 1; r --> RANK_1;) {
|
||||
for (file_t f = FILE_A; f <= FILE_H;) {
|
||||
square_t sq = sq_make(f, r);
|
||||
piece_t piece = pos->board[sq];
|
||||
|
16
src/piece.h
16
src/piece.h
@@ -24,26 +24,28 @@
|
||||
* C: 0 for white, 1: black
|
||||
* PPP: pawn (1), knight, bishop, rook, queen, king (6)
|
||||
*/
|
||||
typedef enum {
|
||||
enum {
|
||||
WHITE, BLACK,
|
||||
COLOR_MAX
|
||||
} color_t;
|
||||
};
|
||||
typedef u8 color_t;
|
||||
|
||||
typedef enum {
|
||||
enum {
|
||||
ALL_PIECES = 0, /* 'all pieces' bitboard */
|
||||
NO_PIECE_TYPE = 0,
|
||||
PAWN = 1, KNIGHT, BISHOP, ROOK, QUEEN, KING,
|
||||
PIECE_TYPE_MAX = 7 /* bit 4 */
|
||||
} piece_type_t;
|
||||
};
|
||||
typedef u8 piece_type_t;
|
||||
|
||||
typedef enum __piece_e {
|
||||
enum __piece_e {
|
||||
EMPTY = 0,
|
||||
NO_PIECE = 0,
|
||||
W_PAWN = PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
||||
B_PAWN = PAWN | 8, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING,
|
||||
PIECE_MAX
|
||||
} piece_t;
|
||||
|
||||
};
|
||||
typedef u8 piece_t;
|
||||
/* default values for midgame, endgame
|
||||
*/
|
||||
#define E_VAL_MID 0
|
||||
|
@@ -43,14 +43,20 @@ typedef struct __pos_s {
|
||||
* This allows a memcpy on this data (to save/restore position state).
|
||||
*/
|
||||
struct_group_tagged(state_s, state,
|
||||
|
||||
/* 64 bits */
|
||||
struct state_s *prev;
|
||||
hkey_t key;
|
||||
|
||||
/* 16 bits */
|
||||
u16 plycount; /* plies so far, start from 1 */
|
||||
move_t move;
|
||||
|
||||
/* 8 bits */
|
||||
square_t en_passant;
|
||||
castle_rights_t castle;
|
||||
int clock_50;
|
||||
int plycount; /* plies so far, start from 1 */
|
||||
piece_t captured; /* only used in move_undo */
|
||||
move_t move;
|
||||
struct state_s *prev;
|
||||
u8 clock_50;
|
||||
);
|
||||
eval_t eval;
|
||||
bitboard_t checkers; /* opponent checkers */
|
||||
|
@@ -53,7 +53,7 @@ int main(int __unused ac, __unused char**av)
|
||||
|
||||
pos_set_checkers_pinners_blockers(pos);
|
||||
|
||||
printf("******* %s\n", cur_comment());
|
||||
printf("******* line %d: %s\n", cur_line(), cur_comment());
|
||||
bb_print_multi("checkers", 2, checkers, pos->checkers);
|
||||
bb_print_multi("pinners", 2, pinners, pos->pinners);
|
||||
bb_print_multi("blockers", 2, blockers, pos->blockers);
|
||||
|
Reference in New Issue
Block a user