From e61e1518f4fea6d65424c3ca61b8222878624b31 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Mon, 17 Jun 2024 07:37:22 +0200 Subject: [PATCH] move_do_alt: use &state (as move_do) --- src/move-do.c | 15 +++++++++------ src/move-do.h | 5 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/move-do.c b/src/move-do.c index f8979b8..7f36bf7 100644 --- a/src/move-do.c +++ b/src/move-do.c @@ -101,7 +101,7 @@ pos_t *move_do(pos_t *pos, const move_t move, state_t *state) } else if (ptype == PAWN) { /* pawn non capture or e.p. */ pos->clock_50 = 0; if (from + up + up == to) { /* if pawn double push, set e.p. */ - square_t ep = from + up;; + square_t ep = from + up; if (bb_pawn_attacks[us][ep] & pos->bb[them][PAWN]) { pos->en_passant = ep; key ^= zobrist_ep[EP_ZOBRIST_IDX(pos->en_passant)]; @@ -215,7 +215,7 @@ pos_t *move_undo(pos_t *pos, const move_t move, const state_t *state) /** * move_{do,undo}_alt - alternative move_do/move_undo (to experiment) */ -pos_t *move_do_alt(pos_t *pos, const move_t move) //, state_t *state) +pos_t *move_do_alt(pos_t *pos, const move_t move, state_t *state) { color_t us = pos->turn, them = OPPONENT(us); square_t from = move_from(move), to = move_to(move); @@ -226,6 +226,8 @@ pos_t *move_do_alt(pos_t *pos, const move_t move) //, state_t *state) int up = sq_up(us); hkey_t key = pos->key; + *state = pos->state; /* save irreversible changes */ + /* update key: switch turn, reset castling and ep */ key ^= zobrist_turn; key ^= zobrist_castling[pos->castle]; @@ -267,14 +269,15 @@ pos_t *move_do_alt(pos_t *pos, const move_t move) //, state_t *state) } else if (ptype == PAWN) { /* pawn non capture or e.p. */ pos->clock_50 = 0; if (from + up + up == to) { /* if pawn double push, set e.p. */ - square_t ep = from + up;; + square_t ep = from + up; if (bb_pawn_attacks[us][ep] & pos->bb[them][PAWN]) { pos->en_passant = ep; key ^= zobrist_ep[EP_ZOBRIST_IDX(pos->en_passant)]; } } else if (is_enpassant(move)) { /* clear grabbed pawn */ square_t grabbed = to - up; - key ^= zobrist_pieces[pos->board[grabbed]][grabbed]; + piece_t pc = pos->board[grabbed]; + key ^= zobrist_pieces[pc][grabbed]; pos_clr_sq(pos, grabbed); } } @@ -321,7 +324,7 @@ pos_t *move_do_alt(pos_t *pos, const move_t move) //, state_t *state) return pos; } -pos_t *move_undo_alt(pos_t *pos, const move_t move) +pos_t *move_undo_alt(pos_t *pos, const move_t move, const state_t *state) { color_t them = pos->turn, us = OPPONENT(them); square_t from = move_from(move), to = move_to(move); @@ -355,7 +358,7 @@ pos_t *move_undo_alt(pos_t *pos, const move_t move) pos_set_sq(pos, grabbed, MAKE_PIECE(PAWN, them)); } - //pos->state = *state; /* restore irreversible changes */ + pos->state = *state; /* restore irreversible changes */ pos->turn = us; return pos; } diff --git a/src/move-do.h b/src/move-do.h index 1bfe032..17ca7dd 100644 --- a/src/move-do.h +++ b/src/move-do.h @@ -19,7 +19,8 @@ pos_t *move_do(pos_t *pos, const move_t move, state_t *state); pos_t *move_undo(pos_t *pos, const move_t move, const state_t *state); -pos_t *move_do_alt(pos_t *pos, const move_t move);//, state_t *state); -pos_t *move_undo_alt(pos_t *pos, const move_t move);//, const state_t *state); +/* new version testing */ +pos_t *move_do_alt(pos_t *pos, const move_t move, state_t *state); +pos_t *move_undo_alt(pos_t *pos, const move_t move, const state_t *state); #endif /* MOVE_DO_H */