add a struct_group for move_do() irreversible changes

This commit is contained in:
2024-03-17 17:34:21 +01:00
parent 49302c7a60
commit 9c2e76442d
2 changed files with 26 additions and 12 deletions

View File

@@ -95,10 +95,14 @@ pos_t *pos_clear(pos_t *pos)
# endif
pos->node_count = 0;
pos->turn = WHITE;
pos->clock_50 = 0;
pos->plycount = 0;
pos->en_passant = SQUARE_NONE;
pos->castle = 0;
pos->clock_50 = 0;
pos->plycount = 0;
for (square_t sq = A1; sq <= H8; ++sq)
pos->board[sq] = EMPTY;
for (color_t color = WHITE; color <= BLACK; ++color) {
for (piece_type_t piece = 0; piece <= KING; ++piece)
@@ -107,12 +111,12 @@ pos_t *pos_clear(pos_t *pos)
pos->king[color] = SQUARE_NONE;
}
for (square_t sq = A1; sq <= H8; ++sq)
pos->board[sq] = EMPTY;
pos->moves.curmove = 0;
pos->moves.nmoves = 0;
pos->checkers = 0;
pos->pinners = 0;
pos->blockers = 0;
//pos->moves.curmove = 0;
pos->moves.nmoves = 0;
return pos;
}

View File

@@ -18,6 +18,7 @@
#include "brlib.h"
#include "bitops.h"
#include "struct-group.h"
#include "chessdefs.h"
#include "bitboard.h"
@@ -28,19 +29,28 @@
typedef struct __pos_s {
u64 node_count; /* evaluated nodes */
int turn; /* WHITE or BLACK */
u16 clock_50;
u16 plycount; /* plies so far, start is 0 */
square_t king[2]; /* dup with bb, faster retrieval */
square_t en_passant;
castle_rights_t castle;
/* data which cannot be recovered by move_undo
* following data can be accessed either directly, either via "movesave"
* structure name.
* For example, pos->en_passant and pos->movesave.en_passant are the same.
* This allows a memcpy on this data (to save/restore position state).
*/
struct_group_tagged(movesave, movesave,
square_t en_passant;
castle_rights_t castle;
u16 clock_50;
u16 plycount; /* plies so far, start is 0 */
);
piece_t board[BOARDSIZE];
bitboard_t bb[2][PIECE_TYPE_MAX]; /* bb[0][PAWN], bb[1][ALL_PIECES] */
bitboard_t controlled[2]; /* unsure */
square_t king[2]; /* dup with bb, faster retrieval */
bitboard_t checkers; /* opponent checkers */
bitboard_t pinners; /* opponent pinners */
bitboard_t blockers; /* pieces blocking pin */
piece_t board[BOARDSIZE];
movelist_t moves;
} pos_t;