gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] Improved stabilisation in get_next_move_from_list


From: Teun Burgers
Subject: [gnugo-devel] Improved stabilisation in get_next_move_from_list
Date: Wed, 23 Oct 2002 21:19:02 +0200

Gunnar wrote:

> What effects does this have on the performance?

Didn't check that. My idea was that the impact would be small as
it is invoked only in the third branch of the if. There is
of cause the call to bdist to initialise top_dist.

> > +static double bdist(int move);
> > +static double bdist(int move)
> > +{
> 
> There's no requirement to have a forward declaration if the function
> is not referenced before it's defined and it's pointless to have the
> declaration immediately before the definition. In this case I see no
> advantage in having a forward declaration at all.

I thought omitting it would cause a warning but it doesn't. I left it
out.

> I suppose you didn't really intend the function to return a double.

you're right. No need for a double there. I converted to int.

revised patch attached.

Teun
Index: owl.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/owl.c,v
retrieving revision 1.114
diff -u -r1.114 owl.c
--- owl.c       21 Oct 2002 19:47:37 -0000      1.114
+++ owl.c       23 Oct 2002 19:09:33 -0000
@@ -3004,6 +3004,20 @@
   matched_patterns->counter++;
 }
 
+/* compute the squared of the distance of a point on the board
+ * to the center of the board
+ */
+
+static int bdist(int move)
+{
+  /* i = 0:              idist = - (board_size - 1)
+     i = board_size -1 : idist =    board_size - 1
+     */
+  int idist = 2*I(move) - board_size + 1;
+  int jdist = 2*J(move) - board_size + 1;
+  return idist*idist + jdist*jdist;
+}
+
 /* This function searches in the previously stored list of matched patterns
  * for the highest valued unused patterns that have a valid constraint.
  * It returns the moves at the next empty positions in the array (moves[]).
@@ -3046,7 +3060,7 @@
      */
     float top_val = list->pattern_list[top].pattern->value;
     struct pattern *top_pattern = list->pattern_list[top].pattern;
-    int top_move = list->pattern_list[top].move;
+    int top_dist = bdist(list->pattern_list[top].move);
 
     /* Maybe we already know the top entry (if previous call was ended
      * by a value cutoff.
@@ -3059,13 +3073,13 @@
                && list->pattern_list[bottom].pattern < top_pattern)
            || (list->pattern_list[bottom].pattern->value == top_val
                && list->pattern_list[bottom].pattern == top_pattern
-               && list->pattern_list[bottom].move < top_move)) {
+               && bdist(list->pattern_list[bottom].move) < top_dist)) {
          matched_pattern = list->pattern_list[bottom];
          list->pattern_list[bottom] = list->pattern_list[top];
          list->pattern_list[top] = matched_pattern;
          top_val = list->pattern_list[top].pattern->value;
          top_pattern = list->pattern_list[top].pattern;
-         top_move = list->pattern_list[top].move;
+         top_dist = bdist(list->pattern_list[top].move);
        }
       list->ordered_up_to++;
     }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]