From b05de8fd7e95e4dc5bd453d5f2eef5d162629cf0 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Tue, 22 Dec 2009 22:01:31 +0100 Subject: [PATCH] board.ps: Introduce, free() at random game end --- board.h | 5 +++++ playout.c | 3 +++ playout.h | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/board.h b/board.h index 8e349cf..d421119 100644 --- a/board.h +++ b/board.h @@ -133,6 +133,11 @@ struct board { * is reset only at clear_board. */ void *es; + /* Playout-specific state; persistent through board development, + * but its lifetime is maintained in play_random_game(); it should + * not be set outside of it. */ + void *ps; + /* --- PRIVATE DATA --- */ diff --git a/playout.c b/playout.c index f9cc235..a3852a3 100644 --- a/playout.c +++ b/playout.c @@ -127,5 +127,8 @@ play_random: if (ownermap) board_ownermap_fill(ownermap, b); + if (b->ps) + free(b->ps); + return result; } diff --git a/playout.h b/playout.h index 4b6bf59..93260b1 100644 --- a/playout.h +++ b/playout.h @@ -16,7 +16,9 @@ struct playout_policy; /* Initialize policy data structures for new playout; subsequent choose calls * (but not assess/permit calls!) will all be made on the same board; if * setboard is used, it is guaranteed that choose will pick all moves played - * on the board subsequently. */ + * on the board subsequently. The routine is expected to initialize b->ps + * with internal data. At the playout end, b->ps will be simply free()d, + * so make sure all data is within single allocated block. */ typedef void (*playoutp_setboard)(struct playout_policy *playout_policy, struct board *b); /* Pick the next playout simulation move. */ typedef coord_t (*playoutp_choose)(struct playout_policy *playout_policy, struct board *b, enum stone to_play); @@ -38,6 +40,7 @@ struct playout_policy { playoutp_choose choose; playoutp_assess assess; playoutp_permit permit; + /* Particular playout policy's internal data. */ void *data; }; -- 2.11.4.GIT