gnugo-devel
[Top][All Lists]

## [gnugo-devel] etiquette_1_25.1

 From: Arend Bayer Subject: [gnugo-devel] etiquette_1_25.1 Date: Tue, 12 Feb 2002 15:48:31 +0100 (CET)

``` - fuseki player taught etiquette

For a change, here comes a patch with smaller regression delta I hope.

Not only is it traditional japanese etiquette for black to start in the
upper right (and for white to continue in the upper left in a symmetric
position), but its also a standard for sgf notations etc. As I have
been taught this quite early in Go childhood, it hurt me every time
GNU Go violated that convention... :)

Arend

Index: engine/fuseki.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/fuseki.c,v
retrieving revision 1.13
diff -u -r1.13 fuseki.c
--- engine/fuseki.c     2 Feb 2002 19:05:12 -0000       1.13
+++ engine/fuseki.c     12 Feb 2002 14:40:47 -0000
@@ -47,6 +47,12 @@
#define LOWER_LEFT  2
#define LOWER_RIGHT 3

+/* Global variables remembering which symmetries the position has. */
+int horizontally_symmetric; /* symmetry with respect to K column */
+int vertically_symmetric;   /* symmetry with respect to 10 row */
+int diagonally_symmetric;   /* ... with respect to diagonal from UR to LL */
+
+
/* This value must be lower than the value for an ongoing joseki.
* (Gets multiplied with board_size / 19.)
*/
@@ -71,6 +77,29 @@
return 1;
}

+/* This function sets the global variables indicating symmetries of the
+ * position. (Important for etiquette.)
+ */
+static void
+set_symmetries()
+{
+  int i, j;
+  horizontally_symmetric = 1;
+  vertically_symmetric = 1;
+  diagonally_symmetric = 1;
+  for (i = 0; i < board_size
+              && (vertically_symmetric || horizontally_symmetric
+                 || diagonally_symmetric); i++)
+    for (j = 0; j < board_size; j++) {
+      if (board[POS(i, j)] != board[POS(board_size - 1 - i, j)])
+       vertically_symmetric = 0;
+      if (board[POS(i, j)] != board[POS(i, board_size - 1 - j)])
+       horizontally_symmetric = 0;
+      if (board[POS(i, j)]
+         != board[POS(board_size - 1 - i, board_size - 1 - j)])
+       horizontally_symmetric = 0;
+    }
+}

/* The corner moves. */

@@ -177,15 +206,41 @@
}

+/* Announce move, but check for politeness first. */
static void
-announce_move(int move, int val)
+announce_move(int move, int val, int color)
{
+  int i, j;
/* This shouldn't happen. */
if (board[move] != EMPTY)
return;
-
-  TRACE("Fuseki Player suggests %1m with value %d\n", move, val);
-  set_minimum_move_value(move, val);
+
+  /* Politeness: Black plays in lower right half of upper right corner first.
+   * White plays in upper left half of lower left corner first.
+   * (Not sure whether this is correct for handicap games. Is this an
+   * urgent FIXME? :-) )
+   */
+  if (horizontally_symmetric) {
+    i = I(move);
+    j = J(move);
+    if ((2 * j < board_size - 1) ^ (color == WHITE))
+      move = POS(i, board_size - 1 - j);
+  }
+  if (vertically_symmetric) {
+    i = I(move);
+    j = J(move);
+    if ((2 * i > board_size - 1) ^ (color == WHITE))
+      move = POS(board_size - 1 - i, j);
+  }
+  if (diagonally_symmetric) {
+    i = I(move);
+    j = J(move);
+    if ((board_size - 1 - j > i) ^ (color == WHITE))
+      move = POS(board_size - 1 - j, board_size - 1 - i);
+  }
+
+  if (set_minimum_move_value(move, val))
+    TRACE("Fuseki Player suggests %1m with value %d\n", move, val);
}

@@ -262,7 +317,7 @@
* matter much since the intention is that we should play this move
* whatever the rest of the analysis thinks.
*/
-  announce_move(fuseki_moves[k], 75);
+  announce_move(fuseki_moves[k], 75, color);

/* Also make sure the other considered moves can be seen in the
* traces and in the output file.
@@ -285,6 +340,8 @@
/* Return immediately if --disable_fuseki option used. */
if (disable_fuseki)
return;
+
+  set_symmetries();

/* Search in fuseki database unless disabled by --nofusekidb option. */
if (fusekidb && search_fuseki_database(color))
@@ -300,7 +357,7 @@
/* For boards of size 11x11 or smaller we first go for the center point. */
int middle = board_size/2;
if (openregion(middle-2, middle+2, middle-2, middle+2)) {
-      announce_move(POS(middle, middle), 45);
+      announce_move(POS(middle, middle), 45, color);
}
}

@@ -316,22 +373,22 @@

if (openregion(0, width-1, board_size-width, board_size-1)) {
choose_corner_move(UPPER_RIGHT, &i, &j);
-    announce_move(POS(i, j), empty_corner_value);
+    announce_move(POS(i, j), empty_corner_value, color);
}

if (openregion(board_size-width, board_size-1, 0, width-1)) {
choose_corner_move(LOWER_LEFT, &i, &j);
-    announce_move(POS(i, j), empty_corner_value);
+    announce_move(POS(i, j), empty_corner_value, color);
}
if (openregion(board_size-width, board_size-1,
board_size-width, board_size-1)) {
choose_corner_move(LOWER_RIGHT, &i, &j);
-    announce_move(POS(i, j), empty_corner_value);
+    announce_move(POS(i, j), empty_corner_value, color);
}

if (openregion(0, width-1, 0, width-1)) {
choose_corner_move(UPPER_LEFT, &i, &j);
-    announce_move(POS(i, j), empty_corner_value);
+    announce_move(POS(i, j), empty_corner_value, color);
}
}

Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.79
diff -u -r1.79 liberty.h
--- engine/liberty.h    11 Feb 2002 04:07:12 -0000      1.79
+++ engine/liberty.h    12 Feb 2002 14:40:52 -0000
@@ -343,7 +343,7 @@
-void set_minimum_move_value(int pos, float value);
+int  set_minimum_move_value(int pos, float value);
void set_maximum_move_value(int pos, float value);
void set_minimum_territorial_value(int pos, float value);
void set_maximum_territorial_value(int pos, float value);
Index: engine/move_reasons.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/move_reasons.c,v
retrieving revision 1.66
diff -u -r1.66 move_reasons.c
--- engine/move_reasons.c       1 Feb 2002 16:43:53 -0000       1.66
+++ engine/move_reasons.c       12 Feb 2002 14:40:58 -0000
@@ -1333,12 +1333,15 @@
/*
* Set a minimum allowed value for the move.
*/
-void
+int
set_minimum_move_value(int pos, float value)
{
ASSERT_ON_BOARD1(pos);
-  if (value > move[pos].min_value)
+  if (value > move[pos].min_value) {
move[pos].min_value = value;
+    return 1;
+  }
+  return 0;
}

/*

```