add M_PR_NL option in move_print()

This commit is contained in:
2023-07-09 15:53:57 +02:00
parent 0b787c8a90
commit 48319cf21a
5 changed files with 30 additions and 21 deletions

View File

@@ -98,7 +98,7 @@ int main(int ac, char**av)
pos_t *pos; pos_t *pos;
eval_t res; eval_t res;
debug_init(5, stderr); debug_init(5, stderr, true);
piece_pool_init(); piece_pool_init();
moves_pool_init(); moves_pool_init();

View File

@@ -179,7 +179,7 @@ int main(int ac, char**av)
{ {
pos_t *pos; pos_t *pos;
debug_init(5, stderr); debug_init(5, stderr, true);
piece_pool_init(); piece_pool_init();
pos_pool_init(); pos_pool_init();
pos = pos_get(); pos = pos_get();

View File

@@ -73,18 +73,19 @@ void moves_pool_stats()
* M_PR_NCAPT: print move if non capture * M_PR_NCAPT: print move if non capture
* M_PR_NUM: print also move number * M_PR_NUM: print also move number
* M_PR_LONG: print long notation * M_PR_LONG: print long notation
* M_PR_NL: print a newline after move
* *
* @return: 0 if nothing printed, 1 otherwise * @return: 0 if nothing printed, 1 otherwise
*/ */
int move_print(int movenum, move_t *move, move_flags_t flags) int move_print(int movenum, move_t *move, move_flags_t flags)
{ {
if (flags & M_PR_CAPT && !(move->flags & M_CAPTURE)) { if ((flags & M_PR_CAPT) && !(move->flags & M_CAPTURE)) {
# ifdef DEBUG_MOVE # ifdef DEBUG_MOVE
log_i(9, "skipping capture & %#04x\n", move->flags); log_i(9, "skipping capture & %#04x\n", move->flags);
# endif # endif
return 0; return 0;
} }
if (flags & M_PR_NCAPT && move->flags & M_CAPTURE) { if ((flags & M_PR_NCAPT) && (move->flags & M_CAPTURE)) {
# ifdef DEBUG_MOVE # ifdef DEBUG_MOVE
log_i(9, "skipping !capture & %#04x\n", move->flags); log_i(9, "skipping !capture & %#04x\n", move->flags);
# endif # endif
@@ -119,6 +120,8 @@ int move_print(int movenum, move_t *move, move_flags_t flags)
end: end:
printf(" "); printf(" ");
} }
if (flags & M_PR_NL)
printf("\n");
return 1; return 1;
} }
@@ -660,9 +663,10 @@ void moves_gen_all(pos_t *pos)
{ {
moves_gen(pos, OPPONENT(pos->turn), false, false); moves_gen(pos, OPPONENT(pos->turn), false, false);
moves_gen(pos, pos->turn, true, true); moves_gen(pos, pos->turn, true, true);
moves_gen_king_moves(pos, OPPONENT(pos->turn), true); moves_gen_king_moves(pos, OPPONENT(pos->turn), false);
} }
/** /**
* move_do() - execute move in a duplicated position. * move_do() - execute move in a duplicated position.
* @pos: &pos_t struct on which move will be applied * @pos: &pos_t struct on which move will be applied
@@ -672,13 +676,12 @@ void moves_gen_all(pos_t *pos)
pos_t *move_do(pos_t *pos, move_t *move) pos_t *move_do(pos_t *pos, move_t *move)
{ {
# ifdef DEBUG_MOVE # ifdef DEBUG_MOVE
log_f(3, "++++++++++"); printf("++++++++++ ");
move_print(0, move, 0); move_print(0, move, M_PR_NL | M_PR_LONG | M_PR_NUM);
log(3, "\n");
# endif # endif
pos_t *new = pos_dup(pos); pos_t *new = pos_dup(pos);
piece_t piece = move->piece; piece_t piece = PIECE(move->piece), newpiece = piece, captured = move->capture;
int color = COLOR(piece); int color = COLOR(piece);
square_t from = move->from, to = move->to; square_t from = move->from, to = move->to;
@@ -692,7 +695,7 @@ pos_t *move_do(pos_t *pos, move_t *move)
piece_del(&new->board[to].s_piece->list); piece_del(&new->board[to].s_piece->list);
new->board[to].piece = 0; new->board[to].piece = 0;
new->occupied[OPPONENT(color)] ^= SQ88_2_BB(to); new->occupied[OPPONENT(color)] ^= SQ88_2_BB(to);
new->bb[OPPONENT(color)][PIECETOBB(piece)] ^= SQ88_2_BB(to); new->bb[OPPONENT(color)][PIECETOBB(captured)] ^= SQ88_2_BB(to);
} else { } else {
uchar ep_file = F88(pos->en_passant); uchar ep_file = F88(pos->en_passant);
square_t ep_grab = color == WHITE ? SQ88(ep_file, 4): SQ88(ep_file, 3); square_t ep_grab = color == WHITE ? SQ88(ep_file, 4): SQ88(ep_file, 3);
@@ -700,7 +703,7 @@ pos_t *move_do(pos_t *pos, move_t *move)
piece_del(&new->board[ep_grab].s_piece->list); piece_del(&new->board[ep_grab].s_piece->list);
new->board[ep_grab].piece = 0; new->board[ep_grab].piece = 0;
new->occupied[OPPONENT(color)] ^= SQ88_2_BB(ep_grab); new->occupied[OPPONENT(color)] ^= SQ88_2_BB(ep_grab);
new->bb[OPPONENT(color)][PIECETOBB(piece)] ^= SQ88_2_BB(ep_grab); new->bb[OPPONENT(color)][BB_PAWN] ^= SQ88_2_BB(ep_grab);
} }
} else if (move->flags & M_CASTLE_Q) { } else if (move->flags & M_CASTLE_Q) {
@@ -729,21 +732,25 @@ pos_t *move_do(pos_t *pos, move_t *move)
new->board[rook_from].s_piece = NULL; new->board[rook_from].s_piece = NULL;
} }
if (move->flags & M_PROMOTION) {
log(2, "promotion to %s\n", P_SYM(move->piece));
new->board[to].piece = move->promotion;
new->board[to].s_piece->square = to;
new->board[to].s_piece->piece = move->promotion;
} else {
new->board[to] = new->board[from]; new->board[to] = new->board[from];
/* fix dest square */ /* fix dest square */
new->board[to].s_piece->square = to; new->board[to].s_piece->square = to;
if (move->flags & M_PROMOTION) {
log(2, "promotion to %s\n", P_SYM(move->promotion));
printf("newpiece=%#x p=%#x\n", move->promotion, PIECE(move->promotion));
newpiece = PIECE(move->promotion);
new->board[to].piece = move->promotion;
new->board[to].s_piece->piece = move->promotion;
} }
/* replace old occupied bitboard by new one */ /* replace old occupied bitboard by new one */
new->occupied[color] ^= SQ88_2_BB(from); new->occupied[color] ^= SQ88_2_BB(from);
new->occupied[color] |= SQ88_2_BB(to); new->occupied[color] |= SQ88_2_BB(to);
new->bb[color][PIECETOBB(piece)] ^= SQ88_2_BB(from); new->bb[color][PIECETOBB(piece)] ^= SQ88_2_BB(from);
new->bb[color][PIECETOBB(piece)] |= SQ88_2_BB(to); new->bb[color][PIECETOBB(newpiece)] |= SQ88_2_BB(to);
if (move->flags & M_PROMOTION) {
printf("color=%d bbpiece=%d\n", color, PIECETOBB(newpiece));
bitboard_print(new->bb[color][PIECETOBB(newpiece)]);
}
/* always make "from" square empty */ /* always make "from" square empty */
new->board[from].piece = 0; new->board[from].piece = 0;
@@ -765,7 +772,7 @@ int main(int ac, char**av)
{ {
pos_t *pos; pos_t *pos;
debug_init(5, stderr); debug_init(5, stderr, true);
piece_pool_init(); piece_pool_init();
moves_pool_init(); moves_pool_init();
pos_pool_init(); pos_pool_init();

View File

@@ -35,6 +35,7 @@ typedef unsigned char move_flags_t;
#define M_PR_CAPT 0x01 #define M_PR_CAPT 0x01
#define M_PR_NCAPT 0x02 #define M_PR_NCAPT 0x02
#define M_PR_NUM 0x04 #define M_PR_NUM 0x04
#define M_PR_NL 0x08
#define M_PR_SEPARATE 0x40 /* separate captures */ #define M_PR_SEPARATE 0x40 /* separate captures */
#define M_PR_LONG 0x80 #define M_PR_LONG 0x80
@@ -44,6 +45,7 @@ typedef struct move_s {
piece_t capture; /* captured piece */ piece_t capture; /* captured piece */
piece_t promotion; /* promoted piece */ piece_t promotion; /* promoted piece */
move_flags_t flags; move_flags_t flags;
eval_t negamax;
struct list_head list; /* next move */ struct list_head list; /* next move */
} move_t; } move_t;
@@ -65,4 +67,4 @@ void moves_gen_all(pos_t *pos);
pos_t *move_do(pos_t *pos, move_t *move); pos_t *move_do(pos_t *pos, move_t *move);
void move_undo(pos_t *pos, move_t *move); void move_undo(pos_t *pos, move_t *move);
#endif /* MODE_H */ #endif /* MOVE_H */

View File

@@ -122,7 +122,7 @@ int main(int ac, char**av)
{ {
pos_t *pos; pos_t *pos;
printf("zobi\n");fflush(stdout); printf("zobi\n");fflush(stdout);
debug_init(6, stderr); debug_init(6, stderr, true);
log_f(5, "kfsjdhg\n"); log_f(5, "kfsjdhg\n");
pos_pool_init(); pos_pool_init();
pos = pos_get(); pos = pos_get();