refactor position: now contains board (not board *)

This commit is contained in:
2021-11-12 20:22:20 +01:00
parent bd7d9f8551
commit 451afea6b5
11 changed files with 54 additions and 17 deletions

View File

@@ -168,14 +168,35 @@ pos_t *pos_get()
pos_t *pos = pool_get(pos_pool);
if (pos) {
//printf("sizeof(board)=%lu\n", sizeof (board_t));
pos->board = malloc(sizeof (board_t)*BOARDSIZE);
//pos->board = malloc(sizeof (board_t)*BOARDSIZE);
//printf("board mem: %p-%p\n", pos->board, pos->board+sizeof (board_t));
//if (pos->board)
pos_clear(pos);
//else {
// free(pos);
// pos = NULL;
//}
}
return pos;
}
/* TODO: merge with pos_get - NULL for init, non null for duplicate */
pos_t *pos_dup(pos_t *pos)
{
pos_t *new = pool_get(pos_pool);
if (new) {
//printf("sizeof(board)=%lu\n", sizeof (board_t));
//new->board = malloc(sizeof (board_t)*BOARDSIZE);
//if (!new->board) {
// pool_add(pos_pool, new);
// return NULL;
//}
*new = *pos;
INIT_LIST_HEAD(&new->pieces[WHITE]);
INIT_LIST_HEAD(&new->pieces[BLACK]);
INIT_LIST_HEAD(&new->moves);
//printf("board mem: %p-%p\n", pos->board, pos->board+sizeof (board_t));
if (pos->board)
pos_clear(pos);
else {
free(pos);
pos = NULL;
}
}
return pos;
}