Index: engine/value_moves.c
===================================================================
RCS file: /home/arend/Go/gnugo-rsync/gnugo/engine/value_moves.c,v
retrieving revision 1.171
diff -u -p -r1.171 value_moves.c
--- engine/value_moves.c	11 Jan 2007 20:35:48 -0000	1.171
+++ engine/value_moves.c	24 Apr 2007 23:23:25 -0000
@@ -2977,12 +2977,30 @@ estimate_strategical_value(int pos, int 
 	|| (owl_move_reason_known(pos, aa)
 	    && dragon[aa].status == CRITICAL)
 	|| move_reason_known(pos, SEMEAI_MOVE, aa)) {
+      float excess_value;
+      int our_dragon = (color == worm[aa].color);
+      float dragon_ter_val = 2 * DRAGON2(aa).strategic_size;
+
+      if ((our_dragon && defense_move_known(pos, aa) == WIN)
+	  || (!our_dragon && attack_move_known(pos, aa) == WIN)) {
+	excess_value = dragon_ter_val - move[pos].territorial_value;
+	if (excess_value > 0.0) {
+	  /* We haven't counted all the territorial value, the most probably
+	   * because of ko situations - repair it here.
+	   * FIXME: We should count values of all ko threats to know how
+	   * much we really gain. As for now 0.75 factor is used. */
+	  excess_value *= 0.75;
+	  TRACE("  %1m: %f - territory underestimation bonus for %1m\n", pos,
+		excess_value, aa);
+	  tot_value += excess_value;
+	}
+      }
+
       /* But if the strategical value was larger than the territorial
        * value (e.g. because connecting to strong dragon) we award the
        * excess value as a bonus.
        */
-      float excess_value = (dragon_value[aa] - 
-			    2 * DRAGON2(aa).strategic_size);
+      excess_value = (dragon_value[aa] - dragon_ter_val);
       if (excess_value > 0.0) {
 	TRACE("  %1m: %f - strategic bonus for %1m\n", pos, excess_value, aa);
 	tot_value += excess_value;
Index: engine/worm.c
===================================================================
RCS file: /home/arend/Go/gnugo-rsync/gnugo/engine/worm.c,v
retrieving revision 1.74
diff -u -p -r1.74 worm.c
--- engine/worm.c	20 Jan 2007 22:14:06 -0000	1.74
+++ engine/worm.c	24 Apr 2007 23:25:45 -0000
@@ -1706,6 +1706,10 @@ defense_callback(int anchor, int color, 
 }
 
 
+/* Find stones, that could live for sure, if player (color) moves
+ * first.
+ */
+
 void
 get_lively_stones(int color, signed char safe_stones[BOARDMAX])
 {
@@ -1713,10 +1717,11 @@ get_lively_stones(int color, signed char
   memset(safe_stones, 0, BOARDMAX * sizeof(*safe_stones));
   for (pos = BOARDMIN; pos < BOARDMAX; pos++)
     if (IS_STONE(board[pos]) && find_origin(pos) == pos) {
-      if ((stackp == 0 && worm[pos].attack_codes[0] == 0) || !attack(pos, NULL)
+      if ((stackp == 0 && worm[pos].attack_codes[0] == 0)
+	   || !attack(pos, NULL)
 	  || (board[pos] == color
-	      && ((stackp == 0 && worm[pos].defense_codes[0] != 0)
-		  || find_defense(pos, NULL))))
+	      && ((stackp == 0 && worm[pos].defense_codes[0] == WIN)
+		  || find_defense(pos, NULL) == WIN)))
 	mark_string(pos, safe_stones, 1);
     }
 }
