gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] A speedup


From: Portela Fernand
Subject: [gnugo-devel] A speedup
Date: Mon, 13 Jan 2003 15:58:46 +0100

A simple idea : when defending, first look for easy ways to gain enough
liberties.

Regression breakage :

global:26      FAIL
global:32      FAIL
nngs2:150      PASS

I haven't checked them very seriously, but I'm rather confident that
they're all accidental.

Performance : 

* reading nodes : -12%
* owl nodes : not worth mentioning (but improved)

I don't have the right tools to make precise timings, but I guess there will
be a nice "boost".

I'm not very familiar with the reading code, so here some issues/thoughts:

* I'm not 100% sure, but I haven't been able to think of a position where
  a ko could mess up the result. So I ignored them, but maybe someone should
  take a (better) look.
* Possibly, it would be enough (and even faster) to use fastlib() instead
  of accuratelib()

/nando

- look first for easy ways to gain enough liberties in do_find_defense()
- new static function fast_defense() in reading.c

Index: engine/reading.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/reading.c,v
retrieving revision 1.98
diff -u -r1.98 reading.c
--- engine/reading.c    12 Jan 2003 20:51:45 -0000      1.98
+++ engine/reading.c    13 Jan 2003 12:05:03 -0000
@@ -987,6 +987,30 @@
 /*                       Defensive functions                        */
 /* ================================================================ */
 
+/* Called by do_find_defense().
+ * Don't think too much if there's an easy way to get enough liberties
+ */
+
+static int
+fast_defense(int str, int *move)
+{
+  int color = board[str];
+  int liberties;
+  int libs[4];
+  int k;
+  int gained;
+
+  liberties = findlib(str, 4, libs);
+  for (k = 0; k < liberties; k++) {
+    gained = accuratelib(libs[k], color, MAX_LIBERTIES, NULL);
+    if (gained > 4
+       || (gained == 4 && stackp > fourlib_depth)) {
+      *move = libs[k];
+      return 1;
+    }
+  }
+  return 0;
+}
 
 /* Like find_defense, but takes the komaster argument. If the
  * opponent is komaster, reading functions will not try
@@ -1046,7 +1070,9 @@
   }
 #endif
 
-  if (liberties == 1)
+  if (fast_defense(str, &xpos))
+    dcode = WIN;
+  else if (liberties == 1)
     dcode = defend1(str, &xpos, komaster, kom_pos);
   else if (liberties == 2)
     dcode = defend2(str, &xpos, komaster, kom_pos);




reply via email to

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