gnugo-devel
[Top][All Lists]
Advanced

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

Re: [gnugo-devel] Crash report for OS X Segmentation fault


From: Gunnar Farneback
Subject: Re: [gnugo-devel] Crash report for OS X Segmentation fault
Date: Thu, 10 Jan 2002 20:28:57 +0100
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/20.7 (sparc-sun-solaris2.7) (with unibyte mode)

Dan wrote:
> > Yes, declaring it static fixes the problem. I'm not familiar with 
> > contributing code or patches to gnugo, so could please one of you guys 
> > fix it? Thanks.
> 
> It's already changed in the CVS. See the patch:
> 
> http://www.gnu.org/software/gnugo/patches/static_moyo_1_20.1

Here's a different solution which substantially reduces the memory
requirements for that function.

Index: engine/dragon.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/dragon.c,v
retrieving revision 1.44
diff -u -r1.44 dragon.c
--- engine/dragon.c     8 Jan 2002 22:34:14 -0000       1.44
+++ engine/dragon.c     10 Jan 2002 08:59:53 -0000
@@ -1574,35 +1574,32 @@
 static void
 compute_surrounding_moyo_sizes(int opposite)
 {
-  int i, j;
   int pos;
-  int m, n;
-  int result[MAX_BOARD * MAX_BOARD];
-  static int moyo_is_adjacent[MAX_BOARD * MAX_BOARD][MAX_MOYOS + 1];
+  int d;
+  int mx[MAX_MOYOS + 1];
   struct moyo_data moyos;
 
   influence_get_moyo_segmentation(opposite, &moyos);
-  for (i = 0; i < number_of_dragons; i++) {
-    result[i] = 0;
-    for (j = 1; j <= moyos.number; j++)
-      moyo_is_adjacent[i][j] = 0;
-  }
-  
-  for (m = 0; m < board_size; m++)
-    for (n = 0; n < board_size; n++) {
-      pos = POS(m, n);
-      if (moyos.segmentation[pos] != 0
-          && board[pos] == moyos.owner[moyos.segmentation[pos]])
-        moyo_is_adjacent[dragon[pos].id][moyos.segmentation[pos]] = 1; 
-    }
-  
-  for (i = 0; i < number_of_dragons; i++) {
-    for (j = 1; j <= moyos.number; j++) {
-      if (moyo_is_adjacent[i][j])
-         result[i] += moyos.size[j];
+
+  memset(mx, 0, sizeof(mx));
+  for (d = 0; d < number_of_dragons; d++) {
+    int this_moyo_size = 0;
+    for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
+      int moyo_number = moyos.segmentation[pos];
+      if (moyo_number == 0
+         || board[pos] != DRAGON(d).color
+         || dragon[pos].id != d
+         || moyos.owner[moyo_number] != board[pos])
+       continue;
+
+      if (mx[moyo_number] != d + 1) {
+       mx[moyo_number] = d + 1;
+       this_moyo_size += moyos.size[moyo_number];
+      }
     }
-    if (result[i] < dragon2[i].moyo)
-       dragon2[i].moyo = result[i];
+    
+    if (this_moyo_size < dragon2[d].moyo)
+      dragon2[d].moyo = this_moyo_size;
   }
 }
 



reply via email to

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