Index: engine/combination.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/combination.c,v
retrieving revision 1.58
diff -u -r1.58 combination.c
--- engine/combination.c	24 Oct 2007 01:56:01 -0000	1.58
+++ engine/combination.c	25 Oct 2007 20:48:56 -0000
@@ -409,14 +409,14 @@
   memset(forbidden, 0, sizeof(forbidden));
   memset(defense_points, 0, sizeof(defense_points));
 
+  compute_aa_status(other, safe_stones);
+  compute_aa_values(other);
+
   /* Accept illegal ko capture here. */
   if (!tryko(move, color, NULL))
     /* Really shouldn't happen. */
     abortgo(__FILE__, __LINE__, "trymove", move);
 
-  compute_aa_status(other, safe_stones);
-  compute_aa_values(other);
-
   increase_depth_values();
 
   aa_val = do_atari_atari(other, &apos, &defense_point, defense_points,
@@ -519,6 +519,8 @@
 
 /* Helper function for computing the aa_status for all opponent's strings.
  * If safe_stones is given, we just copy the information from there.
+ * If called at stackp > 0, safe_stones must be provided since the
+ * dragon_data is not valid then.
  */
 
 static void
@@ -529,6 +531,9 @@
   SGFTree *save_sgf_dumptree = sgf_dumptree;
   int save_count_variations = count_variations;
   int save_verbose = verbose;
+
+  gg_assert(safe_stones || stackp == 0);
+  
   sgf_dumptree = NULL;
   count_variations = 0;
   if (verbose)
@@ -573,8 +578,8 @@
    */
   for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
     if (board[pos] == other
-	&& worm[pos].origin == pos
-	&& worm[pos].liberties == 2
+	&& find_origin(pos) == pos
+	&& countlib(pos) == 2
 	&& aa_status[pos] == ALIVE) {
       int libs[2];
       findlib(pos, 2, libs);
@@ -588,7 +593,7 @@
       if (!owl_substantial(pos)) {
 	int pos2;
 	for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++)
-	  if (ON_BOARD(pos2) && is_worm_origin(pos2, pos))
+	  if (board[pos2] == other && find_origin(pos2) == pos)
 	    aa_status[pos2] = INSUBSTANTIAL;
       }
     }
Index: regression/9x9.tst
===================================================================
RCS file: /cvsroot/gnugo/gnugo/regression/9x9.tst,v
retrieving revision 1.31
diff -u -r1.31 9x9.tst
--- regression/9x9.tst	13 Dec 2006 23:00:26 -0000	1.31
+++ regression/9x9.tst	25 Oct 2007 20:48:57 -0000
@@ -341,3 +341,13 @@
 loadsgf games/cgos/390115.sgf 28
 670 reg_genmove white
 #? [E7]
+
+# There's actually nothing difficult with this position, it's only
+# necessary to avoid a few obvious blunders. The real reason for this
+# test is that a fix for an atari-atari problem introduced a crash in
+# this position. Fixing the crash instead reintroduced an atari-atari
+# mistake in ninestones:220. Let's make sure we won't get a crash here
+# once more. See also tickets #77 and #161.
+loadsgf games/atari-crash.sgf
+680 reg_genmove white
+#? [H7]
Index: regression/ninestones.tst
===================================================================
RCS file: /cvsroot/gnugo/gnugo/regression/ninestones.tst,v
retrieving revision 1.52
diff -u -r1.52 ninestones.tst
--- regression/ninestones.tst	10 Mar 2006 20:03:22 -0000	1.52
+++ regression/ninestones.tst	25 Oct 2007 20:48:57 -0000
@@ -64,6 +64,7 @@
 190 owl_defend J9
 #? [0]*
 
+# See also 9x9:680 and tickets #77 and #161.
 loadsgf games/nngs/thor-gnugo-3.3.12-200212170003.sgf 108
 220 reg_genmove black
 #? [P9|P8]
Index: regression/games/atari-crash.sgf
===================================================================
RCS file: regression/games/atari-crash.sgf
diff -N regression/games/atari-crash.sgf
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ regression/games/atari-crash.sgf	25 Oct 2007 20:48:57 -0000
@@ -0,0 +1,8 @@
+(;GM[1]FF[4]SZ[9]KM[7.5]HA[0]GN[GNU Go 3.7.10 stepped on a bug]
+;B[ec];W[ee];B[cf];W[dd];B[dc];W[cd];B[ge];W[eg];B[gg];W[be];B[eh];W[dg]
+;B[fh];W[cc];B[dh];W[cg];B[fd];W[cb];B[ch];W[fa];B[bg];W[bf];B[ed];W[bh]
+;B[gf];W[gc];B[eb];W[ea];B[da];W[gb];B[db];W[hd];B[gd];W[he];B[hf];W[bi]
+;B[ie];W[ic];B[hb];W[ha];B[ib];W[fb];B[ef];W[df];B[if];W[ca];B[de];W[ff]
+;B[fg];W[ce];B[ac];W[fe];B[ab];W[ad];B[aa];W[ci];B[ah];W[di];B[ag];W[af]
+;B[fi];W[ai];B[ag];W[bg];B[ei]
+)

