[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gnugo-devel] arend_1_24.5: dfa 1D conversion
From: |
Trevor Morris |
Subject: |
Re: [gnugo-devel] arend_1_24.5: dfa 1D conversion |
Date: |
Tue, 05 Feb 2002 21:45:57 -0500 |
At 12:07 AM 2/3/2002 +0100, Arend Bayer wrote:
>It seems to me that one could save maybe 1 or 2 % by some 50 lines of code
>with a specialized "count_approxlib" function, as approxlib is mainly called
>from order_moves in reading.c, where the location of the liberties is
>not used.
I'd already started on something like this for accurate_approxlib,
and it was easy to generalize it. Initial testing on it give about
a 6% improvement on reading.tst.
I'll try to get a patch together tomorrow, but here's the main part:
/* Count the liberties a stone of the given color would get if played
* at (pos). Captures are ignored based on the ignore_capture flag.
* (pos) must be empty. It will fail if there is more than one
* string neighbor of the same color. In this case, the return value
* is -1. Captures are not handled, so if ignore_capture is 0, and
* a capture is required, -1 is returned.
*
* The intent of this function is to be as fast as possible, not
* necessarily complete.
*/
intfastlib(int pos, int color, int ignore_capture) {
int k;
int ally = 0;
int fast_liberties = 0;
int other = OTHER_COLOR(color);
int neighbor;
int neighbor_color;
ASSERT_ON_BOARD1(pos);
ASSERT1(board[pos] == EMPTY, pos);
ASSERT1(IS_STONE(color), pos);
if (!strings_initialized)
init_board();
for (k = 0; k < 4; k++) {
neighbor = pos + delta[k];
if (board[neighbor] == color) {
if (ally) {
if (string_number[ally] != string_number[neighbor]) {
return -1; /* More than 1 ally not implemented (yet).*/
} /* otherwise, do nothing - keep going */
} else {
ally = neighbor;
fast_liberties += countlib(ally) - 1;
}
}
}
for (k = 0; k < 4; k++) {
neighbor = pos + delta[k];
neighbor_color = board[neighbor];
if (!ignore_capture
&& neighbor_color == other
&& countlib(neighbor) == 1) {
return -1;
}
if (neighbor_color == EMPTY) {
if (!ally || !liberty_of_string(neighbor, ally)) {
fast_liberties++;
}
}
}
return fast_liberties;
}