From f3d75ec360beca15191bbfb9ce8ba8fea9397d68 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 8 Oct 2009 13:17:38 +0200 Subject: [PATCH] Stats: Introduce stats_update_value() to recompute the value --- stats.h | 10 ++++++++++ uct/tree.h | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/stats.h b/stats.h index cde3695..e0a57f9 100644 --- a/stats.h +++ b/stats.h @@ -9,4 +9,14 @@ struct move_stats { float value; // wins/playouts }; +/* Recompute value based on wins/playouts. */ +static void stats_update_value(struct move_stats *s); + + +static inline void +stats_update_value(struct move_stats *s) +{ + s->value = (float) s->wins / s->playouts; +} + #endif diff --git a/uct/tree.h b/uct/tree.h index 398839d..9234484 100644 --- a/uct/tree.h +++ b/uct/tree.h @@ -78,8 +78,7 @@ static bool tree_leaf_node(struct tree_node *node); (tree_parity(tree, parity) > 0 ? node->type.wins : node->type.playouts - node->type.wins) /* Recompute the value. */ -#define tree_node_update_value(node, type) \ - ((node)->type.value = (float)(node)->type.wins / (node)->type.playouts) +#define tree_node_update_value(node, type) stats_update_value(&(node)->type) static inline bool tree_leaf_node(struct tree_node *node) -- 2.11.4.GIT