[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnugo-devel] undo speed
From: |
Paul Pogonyshev |
Subject: |
[gnugo-devel] undo speed |
Date: |
Mon, 24 Mar 2003 02:58:15 +0200 |
User-agent: |
KMail/1.4.3 |
this small patch speeds `undo' up by 20%. it's of course still too slow.
now almost all the time (about 97%) is taken by hashtable_clear(). i'm
reluctant to make play_gtp.c have reset_engine() calls delayed (that
is, not after board state changes, but before engine query commands if
it hasn't been reset for the given state yet).
Inge had some plans about changing gnugo caching algorithm. maybe those
will help here too (apart from generally speeding gg up).
step-by-step undoing through a 224 moves game:
before: about 9.4 seconds after: about 7.7 seconds
Paul
--- engine/board.c.orig 2003-03-24 01:55:22.000000000 +0200
+++ engine/board.c 2003-03-24 02:35:10.000000000 +0200
@@ -914,8 +914,16 @@ remove_stone(int pos)
new_position();
}
+
+/* Play a move. Basically the same as play_move() below, but doesn't store
+ * the move in history list.
+ *
+ * Set `update_internals' to zero if you want to play several moves in a
+ * row to avoid overhead caused by new_position(). Don't forget to call
+ * it yourself after all the moves have been played.
+ */
static void
-play_move_no_history(int pos, int color)
+play_move_no_history(int pos, int color, int update_internals)
{
#if CHECK_HASHING
Hash_data oldkey;
@@ -951,7 +959,11 @@ play_move_no_history(int pos, int color)
#endif
#endif
}
- new_position();
+
+ if (update_internals)
+ new_position();
+ else
+ CLEAR_STACKS();
}
/* Load the initial position and replay the first n moves. */
@@ -967,7 +979,9 @@ replay_move_history(int n)
new_position();
for (k = 0; k < n; k++)
- play_move_no_history(move_history_pos[k], move_history_color[k]);
+ play_move_no_history(move_history_pos[k], move_history_color[k], 0);
+
+ new_position();
}
/* Play a move. If you want to test for legality you should first call
@@ -1028,7 +1042,7 @@ play_move(int pos, int color)
move_history_pos[move_history_pointer] = pos;
move_history_pointer++;
- play_move_no_history(pos, color);
+ play_move_no_history(pos, color, 1);
movenum++;
}
- [gnugo-devel] undo speed,
Paul Pogonyshev <=