rename few macros to lowercase, add M_DPUSH move flag
This commit is contained in:
@@ -173,10 +173,6 @@ static __always_inline bitboard_t bb_rank(int rank)
|
|||||||
{
|
{
|
||||||
return RANK_1bb << (rank * 8);
|
return RANK_1bb << (rank * 8);
|
||||||
}
|
}
|
||||||
static __always_inline bitboard_t bb_file(int file)
|
|
||||||
{
|
|
||||||
return FILE_Abb << file;
|
|
||||||
}
|
|
||||||
static __always_inline bitboard_t bb_rel_rank(int rank, color)
|
static __always_inline bitboard_t bb_rel_rank(int rank, color)
|
||||||
{
|
{
|
||||||
return RANK_1bb << (rank * 8);
|
return RANK_1bb << (rank * 8);
|
||||||
@@ -187,11 +183,13 @@ static __always_inline bitboard_t bb_file(int file)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BB_RANK(r) ((u64) RANK_1bb << ((r) * 8))
|
#define bb_rank(r) ((u64) RANK_1bb << ((r) * 8))
|
||||||
#define BB_FILE(f) ((u64) FILE_Abb << (f))
|
#define BB_FILE(f) ((u64) FILE_Abb << (f))
|
||||||
|
|
||||||
#define BB_REL_RANK(r, c) (RANK_1bb << (SQ_REL_RANK((r), (c)) * 8))
|
#define bb_rel_rank(r, c) bb_rank(sq_rel_rank(r, c))
|
||||||
#define BB_REL_FILE(f, c) (FILE_Abb << (SQ_REL_RANK((f), (c))))
|
|
||||||
|
//#define BB_REL_RANK(r, c) (RANK_1bb << (SQ_REL_RANK(r, c) * 8))
|
||||||
|
//#define BB_REL_FILE(f, c) (FILE_Abb << (SQ_REL_RANK((f), (c))))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bb_sq_aligned() - check if two squares are aligned (same file or rank).
|
* bb_sq_aligned() - check if two squares are aligned (same file or rank).
|
||||||
|
@@ -21,8 +21,30 @@
|
|||||||
#define mask(i) ( (u64) (ONE << (i)) )
|
#define mask(i) ( (u64) (ONE << (i)) )
|
||||||
|
|
||||||
#define BOARDSIZE (8*8)
|
#define BOARDSIZE (8*8)
|
||||||
/* relative rank */
|
|
||||||
#define SQ_REL_RANK(r, c) (rank_t)((7 * (c)) ^ r)
|
/**
|
||||||
|
* sq_rel - get relative square
|
||||||
|
* @sq: white point of view square
|
||||||
|
* @c: color
|
||||||
|
*
|
||||||
|
* Get relative (mirrored if @c is BLACK) square.
|
||||||
|
* Example: sq_rel(A1, WHITE) = A1, sq_rel(B2, BLACK) = B7
|
||||||
|
*
|
||||||
|
* @return: Relative square.
|
||||||
|
*/
|
||||||
|
#define sq_rel(sq, c) ((square_t)((sq) ^ (56 * (c))))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sq_rel_rank - get relative rank
|
||||||
|
* @rank: white point of view rank
|
||||||
|
* @c: color
|
||||||
|
*
|
||||||
|
* Get relative (mirrored if @c is BLACK) rank.
|
||||||
|
* Example: sq_rel(RANK_2, WHITE) = RANK_2, sq_rel(RANK_6, BLACK) = RANK_3
|
||||||
|
*
|
||||||
|
* @return: Relative rank.
|
||||||
|
*/
|
||||||
|
#define sq_rel_rank(rank, c) ((rank_t)((7 * (c)) ^ rank))
|
||||||
|
|
||||||
/* castle_t bits structure
|
/* castle_t bits structure
|
||||||
*/
|
*/
|
||||||
@@ -41,10 +63,14 @@ typedef enum {
|
|||||||
|
|
||||||
/* determine is oo or ooo is possible with castle flags f and color c
|
/* determine is oo or ooo is possible with castle flags f and color c
|
||||||
*/
|
*/
|
||||||
#define NORM_CASTLE(f, c) ((f) >> (2 * (c))) /* shift flags to bits 0/1 */
|
#define NORM_CASTLE(f, c) ((f) >> (2 * (c))) /* shift flags to bits 0/1 */
|
||||||
#define CAN_OO(f, c) (NORM_CASTLE(f, c) & CASTLE_K)
|
#define CAN_OO(f, c) (NORM_CASTLE(f, c) & CASTLE_K)
|
||||||
#define CAN_OOO(f, c) (NORM_CASTLE(f, c) & CASTLE_Q)
|
#define CAN_OOO(f, c) (NORM_CASTLE(f, c) & CASTLE_Q)
|
||||||
#define CAN_CASTLE(f, c) (CAN_OO(f, c) | CAN_OOO(f, c))
|
#define CAN_CASTLE(f, c) (CAN_OO(f, c) | CAN_OOO(f, c))
|
||||||
|
|
||||||
|
#define CLR_OO(f, c) (f & ~(CASTLE_K << (2 * (c))))
|
||||||
|
#define CLR_OOO(f, c) (f & ~(CASTLE_Q << (2 * (c))))
|
||||||
|
#define CLR_OO_OOO(f, c) (f & ~((CASTLE_K | CASTLE_Q) << (2 * (c)) ))
|
||||||
|
|
||||||
/* game phases
|
/* game phases
|
||||||
*/
|
*/
|
||||||
|
@@ -81,9 +81,9 @@ static int fen_check(pos_t *pos)
|
|||||||
if (pos->en_passant != SQUARE_NONE) {
|
if (pos->en_passant != SQUARE_NONE) {
|
||||||
rank_t eprank = sq_rank(pos->en_passant);
|
rank_t eprank = sq_rank(pos->en_passant);
|
||||||
file_t epfile = sq_file(pos->en_passant);
|
file_t epfile = sq_file(pos->en_passant);
|
||||||
rank_t rank5 = SQ_REL_RANK(RANK_5, pos->turn);
|
rank_t rank5 = sq_rel_rank(RANK_5, pos->turn);
|
||||||
rank_t rank6 = SQ_REL_RANK(RANK_6, pos->turn);
|
rank_t rank6 = sq_rel_rank(RANK_6, pos->turn);
|
||||||
rank_t rank7 = SQ_REL_RANK(RANK_7, pos->turn);
|
rank_t rank7 = sq_rel_rank(RANK_7, pos->turn);
|
||||||
piece_t pawn = pos->turn == WHITE? B_PAWN: W_PAWN;
|
piece_t pawn = pos->turn == WHITE? B_PAWN: W_PAWN;
|
||||||
if (warn(eprank != rank6 ||
|
if (warn(eprank != rank6 ||
|
||||||
pos->board[sq_make(epfile, rank5)] != pawn ||
|
pos->board[sq_make(epfile, rank5)] != pawn ||
|
||||||
|
@@ -159,6 +159,7 @@ movelist_t *pos_all_legal(const pos_t *pos, movelist_t *dest)
|
|||||||
* - castling: M_CASTLE_{K,Q}
|
* - castling: M_CASTLE_{K,Q}
|
||||||
* - pawn capture (incl. en-passant): M_CAPTURE
|
* - pawn capture (incl. en-passant): M_CAPTURE
|
||||||
* en-passant: M_EN_PASSANT
|
* en-passant: M_EN_PASSANT
|
||||||
|
* - pawn double push: M_DPUSH
|
||||||
* - promotion: M_PROMOTION
|
* - promotion: M_PROMOTION
|
||||||
* - promotion and capture
|
* - promotion and capture
|
||||||
*
|
*
|
||||||
@@ -232,8 +233,8 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* pawn: relative rank and files */
|
/* pawn: relative rank and files */
|
||||||
bitboard_t rel_rank7 = us == WHITE ? RANK_7bb : RANK_2bb;
|
bitboard_t rel_rank7 = bb_rel_rank(RANK_7, us);
|
||||||
bitboard_t rel_rank3 = us == WHITE ? RANK_3bb : RANK_6bb;
|
bitboard_t rel_rank3 = bb_rel_rank(RANK_3, us);
|
||||||
|
|
||||||
/* pawn: ranks 2-6 push 1 and 2 squares */
|
/* pawn: ranks 2-6 push 1 and 2 squares */
|
||||||
movebits = pawn_shift_up(pos->bb[us][PAWN] & ~rel_rank7, us) & empty;
|
movebits = pawn_shift_up(pos->bb[us][PAWN] & ~rel_rank7, us) & empty;
|
||||||
@@ -246,7 +247,7 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
movebits = pawn_shift_up(movebits & rel_rank3, us) & empty;
|
movebits = pawn_shift_up(movebits & rel_rank3, us) & empty;
|
||||||
bit_for_each64(to, tmp1, movebits) {
|
bit_for_each64(to, tmp1, movebits) {
|
||||||
from = pawn_push_up(pawn_push_up(to, them), them);
|
from = pawn_push_up(pawn_push_up(to, them), them);
|
||||||
moves[nmoves++] = move_make(from, to);
|
moves[nmoves++] = move_make_flags(from, to, M_DPUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pawn: ranks 2-6 captures left */
|
/* pawn: ranks 2-6 captures left */
|
||||||
@@ -307,7 +308,7 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
/* castle - Attention ! Castling flags are assumed correct
|
/* castle - Attention ! Castling flags are assumed correct
|
||||||
*/
|
*/
|
||||||
if (!pos->checkers) {
|
if (!pos->checkers) {
|
||||||
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]);
|
||||||
|
10
src/move.h
10
src/move.h
@@ -52,7 +52,8 @@ typedef enum {
|
|||||||
M_PROMOTION = mask(M_OFF_FLAGS + 2),
|
M_PROMOTION = mask(M_OFF_FLAGS + 2),
|
||||||
M_CASTLE_K = mask(M_OFF_FLAGS + 3), /* maybe only one ? */
|
M_CASTLE_K = mask(M_OFF_FLAGS + 3), /* maybe only one ? */
|
||||||
M_CASTLE_Q = mask(M_OFF_FLAGS + 5), /* maybe only one ? */
|
M_CASTLE_Q = mask(M_OFF_FLAGS + 5), /* maybe only one ? */
|
||||||
M_CHECK = mask(M_OFF_FLAGS + 6) /* maybe unknown/useless ? */
|
M_CHECK = mask(M_OFF_FLAGS + 6), /* maybe unknown/useless ? */
|
||||||
|
M_DPUSH = mask(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))
|
||||||
@@ -64,7 +65,7 @@ typedef enum {
|
|||||||
#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 MOVES_MAX 256
|
#define MOVES_MAX 256
|
||||||
|
|
||||||
@@ -126,6 +127,11 @@ static inline move_t move_make_promote_capture(square_t from, square_t to,
|
|||||||
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)
|
||||||
|
{
|
||||||
|
return move | (captured << M_OFF_CAPTURED);
|
||||||
|
}
|
||||||
|
|
||||||
/* moves_print flags
|
/* moves_print flags
|
||||||
*/
|
*/
|
||||||
#define M_PR_CAPT 0x01
|
#define M_PR_CAPT 0x01
|
||||||
|
@@ -299,7 +299,7 @@ void pos_print_raw(const pos_t *pos, const int type)
|
|||||||
*/
|
*/
|
||||||
void pos_print_pieces(const pos_t *pos)
|
void pos_print_pieces(const pos_t *pos)
|
||||||
{
|
{
|
||||||
int bit, count, cur;
|
int sq, count, cur;
|
||||||
char *pname;
|
char *pname;
|
||||||
u64 tmp;
|
u64 tmp;
|
||||||
bitboard_t p;
|
bitboard_t p;
|
||||||
@@ -308,12 +308,12 @@ void pos_print_pieces(const pos_t *pos)
|
|||||||
p = pos->bb[color][piece];
|
p = pos->bb[color][piece];
|
||||||
count = popcount64(p);
|
count = popcount64(p);
|
||||||
cur = 0;
|
cur = 0;
|
||||||
pname = piece_to_cap(piece);
|
pname = piece_to_char(p);
|
||||||
printf("%s(0)%s", pname, count? ":": "");
|
printf("%s(%d)%s", pname, count, count? ":": "");
|
||||||
if (count) {
|
if (count) {
|
||||||
bit_for_each64(bit, tmp, p) {
|
bit_for_each64(sq, tmp, p) {
|
||||||
char cf = sq_file(bit), cr = sq_rank(bit);
|
// char cf = sq_file(bit), cr = sq_rank(bit);
|
||||||
printf("%s%c%c", cur? ",": "", FILE2C(cf), RANK2C(cr));
|
printf("%s%s", cur? ",": "", sq_to_string(sq));
|
||||||
cur++;
|
cur++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user