[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnugo-devel] always init_board()
From: |
Arend Bayer |
Subject: |
[gnugo-devel] always init_board() |
Date: |
Wed, 27 Nov 2002 16:34:21 +0100 (CET) |
Here is a 3% speedup pretty much for free. When GNU Go reached a
new_position(), it set the incremental board data uninitialized, and only
initialized it when it was really needed. However, this meant that all
low-level functions in board.c had to check for this. And the only time
we really saved the call to init_board() was for add_stone(), e.g. for
AB properties in .sgf-files.
So instead we always call init_board() from new_position(). This makes
board.o 1K smaller btw.
Arend
- always keep incremental board data initialized
Index: engine/board.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/board.c,v
retrieving revision 1.57
diff -u -p -r1.57 board.c
--- engine/board.c 20 Nov 2002 20:12:41 -0000 1.57
+++ engine/board.c 27 Nov 2002 15:36:19 -0000
@@ -260,11 +260,6 @@ static int next_stone[BOARDMAX];
/* ---------------------------------------------------------------- */
-/* True if the data structures are up to date for the current
- * board position.
- */
-static int strings_initialized = 0;
-
/* Number of the next free string. */
static int next_string;
@@ -807,7 +802,6 @@ undo_trymove()
gprintf("%opopgo\n");
}
- gg_assert(strings_initialized);
gg_assert(change_stack_pointer - change_stack <= STACK_SIZE);
if (0) {
@@ -1152,9 +1146,6 @@ is_suicide(int pos, int color)
ASSERT_ON_BOARD1(pos);
ASSERT1(board[pos] == EMPTY, pos);
- if (!strings_initialized)
- init_board();
-
/* Check for suicide. */
if (LIBERTY(SOUTH(pos))
|| (ON_BOARD(SOUTH(pos))
@@ -1928,9 +1919,6 @@ countlib(int str)
{
ASSERT1(IS_STONE(board[str]), str);
- if (!strings_initialized)
- init_board();
-
/* We already know the number of liberties. Just look it up. */
return string[string_number[str]].liberties;
}
@@ -1955,9 +1943,6 @@ findlib(int str, int maxlib, int *libs)
ASSERT1(IS_STONE(board[str]), str);
ASSERT1(libs != NULL, str);
- if (!strings_initialized)
- init_board();
-
/* We already have the list of liberties and only need to copy it to
* libs[].
*
@@ -2047,9 +2032,6 @@ fastlib(int pos, int color, int ignore_c
ASSERT1(board[pos] == EMPTY, pos);
ASSERT1(IS_STONE(color), pos);
- if (!strings_initialized)
- init_board();
-
for (k = 0; k < 4; k++) {
int neighbor = pos + delta[k];
if (board[neighbor] == color) {
@@ -2136,9 +2118,6 @@ approxlib(int pos, int color, int maxlib
return fast_liberties;
}
- if (!strings_initialized)
- init_board();
-
/* Look for empty neighbors and the liberties of the adjacent
* strings of the given color. The algorithm below won't work
* correctly if any of the adjacent strings have more than
@@ -2293,9 +2272,6 @@ accuratelib(int pos, int color, int maxl
return fast_liberties;
}
- if (!strings_initialized)
- init_board();
-
string_mark++;
liberty_mark++;
MARK_LIBERTY(pos);
@@ -2531,9 +2507,6 @@ count_common_libs(int str1, int str2)
ASSERT1(IS_STONE(board[str1]), str1);
ASSERT1(IS_STONE(board[str2]), str2);
- if (!strings_initialized)
- init_board();
-
n = string_number[str1];
liberties1 = string[n].liberties;
@@ -2602,9 +2575,6 @@ find_common_libs(int str1, int str2, int
ASSERT1(IS_STONE(board[str2]), str2);
ASSERT1(libs != NULL, str1);
- if (!strings_initialized)
- init_board();
-
n = string_number[str1];
liberties1 = string[n].liberties;
@@ -2672,9 +2642,6 @@ have_common_lib(int str1, int str2, int
ASSERT1(IS_STONE(board[str1]), str1);
ASSERT1(IS_STONE(board[str2]), str2);
- if (!strings_initialized)
- init_board();
-
n = string_number[str1];
liberties1 = string[n].liberties;
@@ -2717,9 +2684,6 @@ countstones(int str)
ASSERT_ON_BOARD1(str);
ASSERT1(IS_STONE(board[str]), str);
- if (!strings_initialized)
- init_board();
-
return COUNTSTONES(str);
}
@@ -2740,9 +2704,6 @@ findstones(int str, int maxstones, int *
ASSERT_ON_BOARD1(str);
ASSERT1(IS_STONE(board[str]), str);
- if (!strings_initialized)
- init_board();
-
s = string_number[str];
size = string[s].size;
@@ -2769,9 +2730,6 @@ chainlinks(int str, int adj[MAXCHAIN])
ASSERT1(IS_STONE(board[str]), str);
- if (!strings_initialized)
- init_board();
-
/* We already have the list ready, just copy it and fill in the
* desired information.
*/
@@ -2797,9 +2755,6 @@ chainlinks2(int str, int adj[MAXCHAIN],
ASSERT1(IS_STONE(board[str]), str);
- if (!strings_initialized)
- init_board();
-
/* We already have the list ready, just copy the strings with the
* right number of liberties.
*/
@@ -2828,9 +2783,6 @@ chainlinks3(int str, int adj[MAXCHAIN],
ASSERT1(IS_STONE(board[str]), str);
- if (!strings_initialized)
- init_board();
-
/* We already have the list ready, just copy the strings with the
* right number of liberties.
*/
@@ -2865,9 +2817,6 @@ extended_chainlinks(int str, int adj[MAX
ASSERT1(IS_STONE(board[str]), str);
- if (!strings_initialized)
- init_board();
-
/* We already have the list of directly adjacent strings ready, just
* copy it and mark the strings.
*/
@@ -2911,9 +2860,6 @@ find_origin(int str)
{
ASSERT1(IS_STONE(board[str]), str);
- if (!strings_initialized)
- init_board();
-
return string[string_number[str]].origin;
}
@@ -2940,9 +2886,6 @@ is_self_atari(int pos, int color)
ASSERT1(board[pos] == EMPTY, pos);
ASSERT1(IS_STONE(color), pos);
- if (!strings_initialized)
- init_board();
-
/* 1. Try first to solve the problem without much work. */
string_mark++;
@@ -3036,9 +2979,6 @@ is_self_atari(int pos, int color)
ASSERT1(board[pos] == EMPTY, pos);
ASSERT1(IS_STONE(color), pos);
- if (!strings_initialized)
- init_board();
-
/* 1. Try first without really putting the stone on the board. */
/* FIXME: Integrate incremental_sloppy_self_atari() here. */
result = incremental_sloppy_self_atari(pos, color);
@@ -3106,9 +3046,6 @@ neighbor_of_string(int pos, int str)
ASSERT1(IS_STONE(color), str);
ASSERT_ON_BOARD1(pos);
- if (!strings_initialized)
- init_board();
-
s = string_number[str];
if (board[SOUTH(pos)] == color
@@ -3143,9 +3080,6 @@ same_string(int str1, int str2)
ASSERT1(IS_STONE(board[str1]), str1);
ASSERT1(IS_STONE(board[str2]), str2);
- if (!strings_initialized)
- init_board();
-
return string_number[str1] == string_number[str2];
}
@@ -3165,9 +3099,6 @@ adjacent_strings(int str1, int str2)
ASSERT1(IS_STONE(board[str1]), str1);
ASSERT1(IS_STONE(board[str2]), str2);
- if (!strings_initialized)
- init_board();
-
s1 = string_number[str1];
s2 = string_number[str2];
@@ -3201,9 +3132,6 @@ is_ko(int pos, int color, int *ko_pos)
ASSERT_ON_BOARD1(pos);
ASSERT1(color == WHITE || color == BLACK, pos);
- if (!strings_initialized)
- init_board();
-
if (ON_BOARD(SOUTH(pos))) {
if (board[SOUTH(pos)] != other)
return 0;
@@ -3265,9 +3193,6 @@ is_ko_point(int pos)
{
ASSERT_ON_BOARD1(pos);
- if (!strings_initialized)
- init_board();
-
if (board[pos] == EMPTY) {
int color;
if (ON_BOARD(SOUTH(pos)))
@@ -3297,9 +3222,6 @@ does_capture_something(int pos, int colo
ASSERT1(board[pos] == EMPTY, pos);
- if (!strings_initialized)
- init_board();
-
if (board[SOUTH(pos)] == other && LIBERTIES(SOUTH(pos)) == 1)
return 1;
@@ -3329,9 +3251,6 @@ mark_string(int str, char mx[BOARDMAX],
ASSERT1(IS_STONE(board[str]), str);
- if (!strings_initialized)
- init_board();
-
do {
mx[pos] = mark;
pos = NEXT_STONE(pos);
@@ -3420,9 +3339,7 @@ get_trymove_counter()
/* ================================================================ */
-/* Don't trust the incremental string data until it's reinitialized.
- *
- * This function should be called if the board is modified by other
+/* This function should be called if the board is modified by other
* means than do_play_move() or undo_trymove().
* It's also useful to force a recomputation of the strings if we
* don't have any immediate plans to undo the move, because it recovers
@@ -3430,14 +3347,14 @@ get_trymove_counter()
*/
/* We have reached a new position. Increase the position counter and
- * invalidate the incremental strings.
+ * re-initialize the incremental strings.
*/
static void
new_position(void)
{
position_number++;
- strings_initialized = 0;
+ init_board();
}
@@ -3485,9 +3402,6 @@ init_board()
for (s = 0; s < next_string; s++) {
find_liberties_and_neighbors(s);
}
-
- /* Now we can trust the information. */
- strings_initialized = 1;
}
@@ -4199,9 +4113,6 @@ do_play_move(int pos, int color)
int north = NORTH(pos);
int east = EAST(pos);
- if (!strings_initialized)
- init_board();
-
/* Remove captured stones and check for suicide.*/
if (board[south] == other && LIBERTIES(south) == 1)
captured_stones += do_remove_string(string_number[south]);
- [gnugo-devel] always init_board(),
Arend Bayer <=