From 118a8e5c08370b455ffb18c408dca3fd540e9752 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 6 Dec 2010 17:48:13 +0100 Subject: [PATCH] Playout: Support for engine hooks altering policy decisions --- playout.c | 12 ++++++++++-- playout.h | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/playout.c b/playout.c index a72eaab..813194d 100644 --- a/playout.c +++ b/playout.c @@ -46,8 +46,16 @@ play_random_game(struct playout_setup *setup, int passes = is_pass(b->last_move.coord) && b->moves > 0; while (gamelen-- && passes < 2) { - coord_t coord; - coord = policy->choose(policy, setup, b, color); + coord_t coord = pass; + + if (setup->prepolicy_hook) + coord = setup->prepolicy_hook(policy, setup, b, color); + + if (is_pass(coord)) + coord = policy->choose(policy, setup, b, color); + + if (is_pass(coord) && setup->postpolicy_hook) + coord = setup->postpolicy_hook(policy, setup, b, color); if (is_pass(coord)) { play_random: diff --git a/playout.h b/playout.h index 4bd2101..8a757f9 100644 --- a/playout.h +++ b/playout.h @@ -56,14 +56,24 @@ struct playout_policy { /** Playout engine interface: */ +/* Engine hook for forcing moves before doing policy decision. + * Return pass to forward to policy. */ +typedef coord_t (*playouth_prepolicy)(struct playout_policy *playout_policy, struct playout_setup *setup, struct board *b, enum stone color); + +/* Engine hook for choosing moves in case policy did not choose + * a move. + * Return pass to forward to uniformly random selection. */ +typedef coord_t (*playouth_postpolicy)(struct playout_policy *playout_policy, struct playout_setup *setup, struct board *b, enum stone color); + struct playout_setup { unsigned int gamelen; /* Maximal # of moves in playout. */ /* Minimal difference between captures to terminate the playout. * 0 means don't check. */ unsigned int mercymin; - /* XXX: We used to have more, perhaps we will again have more - * in the future. */ + void *hook_data; // for hook to reference its state + playouth_prepolicy prepolicy_hook; + playouth_postpolicy postpolicy_hook; }; -- 2.11.4.GIT