[Pachi] Minor bug

Lauri Paatero Lauri.Paatero at iki.fi
Mon Sep 17 19:50:12 CEST 2012


Hi,

Thanks for good program.
I have been using it in Hactar go in server, mostly it has been working 
fine.

I noticed that in uctp_generic_choose there is bug:
If node->children is excluded or invalid, it may still be returned.
Also if it is best, it is returned for both best and second best.

Below is what I think correct code.

- Lauri

   struct tree_node *
  uctp_generic_choose(struct uct_policy *p, struct tree_node *node, 
struct board *b, enum stone color, coord_t exclude)
  {
-    struct tree_node *nbest = node->children;
-    if (!nbest) return NULL;
-    struct tree_node *nbest2 = nbest->sibling;
+    struct tree_node *nbest = NULL;
+    struct tree_node *nbest2 = NULL;
+
+    if (!node->children) return NULL;

      /* This function is called while the tree is updated by other threads.
       * We rely on node->children being set only after the node has 
been fully expanded. */
-    for (struct tree_node *ni = nbest2; ni; ni = ni->sibling) {
+    for (struct tree_node *ni = node->children; ni; ni = ni->sibling) {
          // we compare playouts and choose the best-explored
          // child; comparing values is more brittle
          if (node_coord(ni) == exclude || ni->hints & TREE_HINT_INVALID)
              continue;
-        if (ni->u.playouts > nbest->u.playouts) {
+        if (nbest==NULL) {
+            nbest = ni;
+        } else if (ni->u.playouts > nbest->u.playouts) {
              nbest2 = nbest;
              nbest = ni;
-        } else if (ni->u.playouts > nbest2->u.playouts) {
+        } else if (nbest2==NULL || ni->u.playouts > nbest2->u.playouts) {
              nbest2 = ni;
          }
      }
      /* Play pass only if we can afford scoring. Call expensive 
uct_pass_is_safe() only if
       * pass is indeed the best move. */
     if (is_pass(node_coord(nbest)) && !uct_pass_is_safe(p->uct, b, 
color, p->uct->pass_all_alive))
         return nbest2;
      return nbest;
  }



More information about the Pachi mailing list