diff --git a/src/chessdefs.h b/src/chessdefs.h index 7d8430a..9301278 100644 --- a/src/chessdefs.h +++ b/src/chessdefs.h @@ -22,13 +22,13 @@ typedef u8 piece_t; enum { E_EMPTY = 0, + E_COLOR, /* LSB */ E_PAWN, E_KNIGHT, E_BISHOP, E_ROOK, E_QUEEN, E_KING, - E_COLOR = 8 }; @@ -36,23 +36,22 @@ enum { */ enum { EMPTY = 0, - PAWN = 1 << (E_PAWN - 1), /* 0x01 00000001 */ - KNIGHT = 1 << (E_KNIGHT - 1), /* 0x02 00000010 */ - BISHOP = 1 << (E_BISHOP - 1), /* 0x04 00000100 */ - ROOK = 1 << (E_ROOK - 1), /* 0x08 00001000 */ - QUEEN = 1 << (E_QUEEN - 1), /* 0x10 00010000 */ - KING = 1 << (E_KING - 1), /* 0x20 00100000 */ + PAWN = 1 << (E_PAWN - 1), /* 0x02 00000010 */ + KNIGHT = 1 << (E_KNIGHT - 1), /* 0x04 00000100 */ + BISHOP = 1 << (E_BISHOP - 1), /* 0x08 00001000 */ + ROOK = 1 << (E_ROOK - 1), /* 0x10 00010000 */ + QUEEN = 1 << (E_QUEEN - 1), /* 0x20 00100000 */ + KING = 1 << (E_KING - 1), /* 0x40 01000000 */ }; #define WHITE 0 /* 0x00 00000000 */ #define BLACK 1 /* 0x01 00000001 */ #define OPPONENT(p) !(p) -#define MASK_PIECE 0x3F /* 00111111 */ -#define MASK_COLOR 0x80 /* 10000000 */ +#define MASK_COLOR 0x01 /* 00000001 */ +#define MASK_PIECE 0x7E /* 01111110 */ #define COLOR(p) ((p) & MASK_COLOR) /* bitmask */ -#define VCOLOR(p) (!!COLOR(p)) /* WHITE/BLACK */ #define PIECE(p) ((p) & MASK_PIECE) #define E_PIECE(p) (ffs64(PIECE(p))) /* convert mask to E_XX */ diff --git a/src/move.c b/src/move.c index 7f4407d..d5c233b 100644 --- a/src/move.c +++ b/src/move.c @@ -186,8 +186,8 @@ static move_t *move_add(pos_t *pos, piece_t piece, square_t from, /* fix dest square */ newpos->board[to].s_piece->square = to; /* replace old occupied bitboard by new one */ - newpos->occupied[VCOLOR(piece)] ^= SQ88_2_BB(from); - newpos->occupied[VCOLOR(piece)] |= SQ88_2_BB(to); + newpos->occupied[COLOR(piece)] ^= SQ88_2_BB(from); + newpos->occupied[COLOR(piece)] |= SQ88_2_BB(to); /* always make "from" square empty */ newpos->board[from].piece = 0; @@ -277,7 +277,6 @@ int pseudo_moves_pawn(pos_t *pos, piece_list_t *ppiece, bool doit) { piece_t piece = PIECE(ppiece->piece); unsigned char color = COLOR(ppiece->piece); - unsigned char vcolor = VCOLOR(ppiece->piece); square_t square = ppiece->square, new; board_t *board = pos->board; unsigned char rank2, rank7, rank5; @@ -319,7 +318,7 @@ int pseudo_moves_pawn(pos_t *pos, piece_list_t *ppiece, bool doit) log_i(4, "pushing pawn %#04x\n", square); # endif //log_f(4, "pawn move mobility\n"); - pos->mobility[vcolor]++; + pos->mobility[color]++; if (doit && (move = move_pawn_add(pos, piece | color, square, new, rank7))) count++; /* push 2 squares */ @@ -330,7 +329,7 @@ int pseudo_moves_pawn(pos_t *pos, piece_list_t *ppiece, bool doit) log_i(4, "pushing pawn %#04x 2 squares\n", square); # endif //log_f(2, "pawn move2 mobility\n"); - pos->mobility[vcolor]++; + pos->mobility[color]++; if (doit && (move = move_pawn_add(pos, piece | color, square, new, rank7))) { count++; @@ -374,10 +373,10 @@ int pseudo_moves_pawn(pos_t *pos, piece_list_t *ppiece, bool doit) # endif if (SQ88_NOK(new)) continue; - pos->controlled[vcolor] |= SQ88_2_BB(new); + pos->controlled[color] |= SQ88_2_BB(new); if (board[new].piece && COLOR(board[new].piece) != color) { //log_f(2, "pawn capture mobility\n"); - pos->mobility[vcolor]++; + pos->mobility[color]++; if (doit && ((move = move_pawn_add(pos, piece | color, square, new, rank7)))) count++; @@ -476,7 +475,6 @@ int pseudo_moves_gen(pos_t *pos, piece_list_t *ppiece, bool doit) { piece_t piece = PIECE(ppiece->piece); unsigned char color = COLOR(ppiece->piece); - unsigned char vcolor = VCOLOR(ppiece->piece); struct vector *vector = vectors+piece; square_t square = ppiece->square; unsigned char ndirs = vector->ndirs; @@ -516,10 +514,10 @@ int pseudo_moves_gen(pos_t *pos, piece_list_t *ppiece, bool doit) //bitboard_print(new_bitboard); # endif - pos->controlled[vcolor] |= bb_new;; + pos->controlled[color] |= bb_new;; /* king: do not move to opponent controlled square */ - if (piece == KING && pos->controlled[OPPONENT(vcolor)] & bb_new) { + if (piece == KING && pos->controlled[OPPONENT(color)] & bb_new) { # ifdef DEBUG_MOVE log_i(2, "%s king cannot move to %c%c\n", IS_WHITE(color)? "white": "black", @@ -528,9 +526,9 @@ int pseudo_moves_gen(pos_t *pos, piece_list_t *ppiece, bool doit) break; } - if (bb_new & pos->occupied[vcolor]) { - //bitboard_print(pos->occupied[vcolor]); - //bitboard_print(pos->occupied[OPPONENT(vcolor)]); + if (bb_new & pos->occupied[color]) { + //bitboard_print(pos->occupied[color]); + //bitboard_print(pos->occupied[OPPONENT(color)]); # ifdef DEBUG_MOVE log_i(2, "BB: skipping %#llx [%c%c] (same color piece)\n", new, FILE2C(GET_F(new)), RANK2C(GET_R(new))); @@ -540,7 +538,7 @@ int pseudo_moves_gen(pos_t *pos, piece_list_t *ppiece, bool doit) /* we are sure the move is valid : we create move */ //log_f(2, "piece mobility\n"); - pos->mobility[vcolor]++; + pos->mobility[color]++; if (doit && color == pos->turn) { if ((move = move_add(pos, ppiece->piece, square, new))) { count++; diff --git a/src/piece.c b/src/piece.c index aa6ee7f..65a14e6 100644 --- a/src/piece.c +++ b/src/piece.c @@ -63,7 +63,7 @@ void piece_pool_stats() piece_list_t *piece_add(pos_t *pos, piece_t piece, square_t square) { piece_list_t *new; - short color = VCOLOR(piece); + short color = COLOR(piece); # ifdef DEBUG_PIECE log_f(3, "piece=%02x square=%02x\n", piece, square);