gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] arend_1_32.4: hash_(re_)init for new game (revision of gun


From: Arend Bayer
Subject: [gnugo-devel] arend_1_32.4: hash_(re_)init for new game (revision of gunnar_1_32.7)
Date: Thu, 11 Apr 2002 21:36:29 +0200 (CEST)

I have two more comments to the random seed patches.

1. Gunnar's patches have changed the behaviour when the opponent takes back
a move and replays it. Before the random seed patches GNU Go would have made
a new choice among equally valued moves, now it will deterministically make
the identical choice.
One could argue which behaviour is preferable, I like the old one better.
But the new one is easier for debugging, so I don't suggest changing this.

2. Both the unlikely double hash collision, as well as the organization
of the hash table in case of (single) hash collisions depend on the
random seed that was used when the has values got initialized. This
is an explicit intergame dependency. I think we all agree that intergame
dependencies are bad (I'd consider them bugs), and hence I've added
the necessary 2 lines to the patch gunnar_1_32.7 that should fix this.

The patch isn't tested very much so far, as good testing will be possible
once twogtp works with with Gunnar's patch. (Then we should be able to
to replay a single game of a twogtp series using the random seeds from
the sgf-file, and e.g. get identical --statistics output.)

Arend
 
 - call hash_init() with each call to update_random_seed() for new game
 
(Moved prototype of hash_init from hash.h to liberty.h for this purpose.)
 
Index: engine/genmove.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/genmove.c,v
retrieving revision 1.36
diff -u -r1.36 genmove.c
--- engine/genmove.c    7 Apr 2002 15:27:35 -0000       1.36
+++ engine/genmove.c    11 Apr 2002 18:24:14 -0000
@@ -67,6 +67,14 @@
 void
 reset_engine()
 {
+  /* To improve the reproducability of games, we restart the random
+   * number generator with the same seed for each move. Thus we don't
+   * have to know how many previous moves have been played, nor
+   * actually play through them, in order to get the right random
+   * numbers.
+   */
+  gg_srand(random_seed);
+
   /* Initialize things for hashing of positions. */
   reading_cache_clear();
   hashdata_recalc(&hashdata, board, board_ko_pos);
Index: engine/hash.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/hash.h,v
retrieving revision 1.7
diff -u -r1.7 hash.h
--- engine/hash.h       25 Mar 2002 04:47:27 -0000      1.7
+++ engine/hash.h       11 Apr 2002 18:24:14 -0000
@@ -133,7 +133,6 @@
 } Hash_data;
 
 
-void hash_init(void);
 #if FULL_POSITION_IN_HASH
 int hashposition_compare(Hashposition *pos1, Hashposition *pos2);
 void hashposition_dump(Hashposition *pos, FILE *outfile);
Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.94
diff -u -r1.94 liberty.h
--- engine/liberty.h    30 Mar 2002 20:29:22 -0000      1.94
+++ engine/liberty.h    11 Apr 2002 18:24:19 -0000
@@ -165,6 +165,9 @@
 void start_timer(int n);
 double time_report(int n, const char *occupation, int move, double mintime);
 
+void update_random_seed(void);
+void hash_init(void);
+
 
 /* Play at (pos) and then count the liberties. */
 int accurate_approxlib(int pos, int color, int maxlib, int *libs);
Index: engine/move_reasons.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/move_reasons.c,v
retrieving revision 1.78
diff -u -r1.78 move_reasons.c
--- engine/move_reasons.c       7 Apr 2002 12:38:44 -0000       1.78
+++ engine/move_reasons.c       11 Apr 2002 18:24:26 -0000
@@ -103,24 +103,6 @@
   next_all = 0;
   next_eye = 0;
   next_lunch = 0;
-
-  /* To improve the reproducability of games, we restart the random
-   * number generator with the same seed for each move. Thus we don't
-   * have to know how many previous moves have been played, nor
-   * actually play through them, in order to get the right random
-   * numbers.
-   *
-   * Comment: This means we might set these numbers only once instead
-   *          of before each move. This is not without complications
-   *          though, since we don't have full control of when the
-   *          random seed is changed. Better to do it for each move.
-   *
-   * Comment 2: While this is a good idea, we're not yet quite ready
-   *            to make use of it.
-   */
-#if 0
-  gg_srand(random_seed);
-#endif
   
   for (i = 0; i < board_size; i++)
     for (j = 0; j < board_size; j++) {
Index: engine/utils.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/utils.c,v
retrieving revision 1.42
diff -u -r1.42 utils.c
--- engine/utils.c      20 Mar 2002 17:20:13 -0000      1.42
+++ engine/utils.c      11 Apr 2002 18:24:32 -0000
@@ -1740,6 +1740,18 @@
   return dt;
 }
 
+/* Update the random seed with the current value in the random sequence. */
+void
+update_random_seed(void)
+{
+  random_seed = gg_rand();
+  /* Since random seed 0 has a special interpretation when given as
+   * command line argument with the -r option, we make sure to avoid
+   * it.
+   */
+  if (random_seed == 0)
+    random_seed = 1;
+}
 
 
 /*
Index: interface/play_ascii.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_ascii.c,v
retrieving revision 1.16
diff -u -r1.16 play_ascii.c
--- interface/play_ascii.c      31 Mar 2002 18:48:08 -0000      1.16
+++ interface/play_ascii.c      11 Apr 2002 18:24:36 -0000
@@ -988,6 +988,9 @@
     passes = 0;
     showdead = 0;
     sgf_initialized = 0;
+    /* Play a different game next time. */
+    update_random_seed();
+    hash_init();
   }
   printf("\nThanks for playing GNU Go.\n\n");
 }
Index: interface/play_gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v
retrieving revision 1.70
diff -u -r1.70 play_gtp.c
--- interface/play_gtp.c        7 Apr 2002 17:00:31 -0000       1.70
+++ interface/play_gtp.c        11 Apr 2002 18:24:46 -0000
@@ -347,12 +347,25 @@
 gtp_set_boardsize(char *s, int id)
 {
   int boardsize;
+  int pos;
+  
   if (sscanf(s, "%d", &boardsize) < 1)
     return gtp_failure(id, "boardsize not an integer");
   
   if (boardsize < MIN_BOARD || boardsize > MAX_BOARD)
     return gtp_failure(id, "unacceptable boardsize");
 
+  /* If this is called with a non-empty board, we assume that a new
+   * game will be started, for which we want a new random seed.
+   */
+  for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
+    if (ON_BOARD(pos) && board[pos] != EMPTY) {
+      update_random_seed();
+      hash_init();
+      break;
+    }
+  }
+  
   board_size = boardsize;
   clear_board();
   gtp_internal_set_boardsize(boardsize);








reply via email to

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