[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnugo-devel] != EMPTY or IS_COLOR ?
From: |
Teun Burgers |
Subject: |
[gnugo-devel] != EMPTY or IS_COLOR ? |
Date: |
Thu, 11 Oct 2001 22:11:33 +0200 |
In the days of the 2-D board
!= EMPTY implied BLACK || WHITE.
With the 1-D board it can also mean GRAY,
unless you made sure that the point is ON_BOARD.
This patch defines a new macro IS_COLOR and as
an example replace != EMPTY tests in worm.c
with IS_COLOR tests. I think this is
safer in the long run
Teun
Index: engine/gnugo.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/gnugo.h,v
retrieving revision 1.15
diff -u -r1.15 gnugo.h
--- engine/gnugo.h 2001/10/11 15:39:37 1.15
+++ engine/gnugo.h 2001/10/11 20:08:44
@@ -63,6 +63,7 @@
#define OTHER_COLOR(color) (WHITE+BLACK-(color))
+#define IS_COLOR(arg) ((arg) == WHITE || (arg) == BLACK)
/* Return codes for reading functions */
Index: engine/worm.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/worm.c,v
retrieving revision 1.14
diff -u -r1.14 worm.c
--- engine/worm.c 2001/10/10 19:05:06 1.14
+++ engine/worm.c 2001/10/11 20:08:54
@@ -488,8 +488,8 @@
for (n = 0; n < board_size; n++) {
int pos = POS(m, n);
if (!is_same_worm(pos, SOUTH(pos))
- && board[pos] != EMPTY
- && board[SOUTH(pos)] != EMPTY) {
+ && IS_COLOR(board[pos])
+ && IS_COLOR(board[SOUTH(pos)])) {
if (worm[pos].attack_codes[0] != 0
&& worm[SOUTH(pos)].attack_codes[0] != 0) {
if (worm[pos].defend_codes[0] == 0
@@ -511,8 +511,8 @@
for (n = 0; n < board_size-1; n++) {
int pos = POS(m, n);
if (!is_same_worm(pos, EAST(pos))
- && board[pos] != EMPTY
- && board[EAST(pos)] != EMPTY) {
+ && IS_COLOR(board[pos])
+ && IS_COLOR(board[EAST(pos)])) {
if (worm[pos].attack_codes[0] != 0
&& worm[EAST(pos)].attack_codes[0] != 0) {
if (worm[pos].defend_codes[0] == 0
@@ -632,7 +632,7 @@
worm[pos].invincible = 0;
worm[pos].unconditional_status = UNKNOWN;
worm[pos].effective_size = 0.0;
- if (board[pos] != EMPTY) {
+ if (IS_COLOR(board[pos])) {
worm[pos].liberties = countlib(pos);
worm[pos].size = countstones(pos);
propagate_worm(pos);
@@ -739,7 +739,7 @@
/* Propagate the effective size values all over the worms. */
for (m = 0; m < board_size; m++)
for (n = 0; n < board_size; n++)
- if (BOARD(m, n) != EMPTY && is_worm_origin(POS(m, n), POS(m, n)))
+ if (IS_COLOR(BOARD(m, n)) && is_worm_origin(POS(m, n), POS(m, n)))
propagate_worm(POS(m, n));
}
@@ -1003,7 +1003,7 @@
int bb = libs[k] + delta[l];
if (!ON_BOARD(bb)
- || board[bb] != EMPTY
+ || IS_COLOR(board[bb])
|| liberty_of_string(bb, pos))
continue;
@@ -1065,7 +1065,7 @@
int bb = libs[k] + delta[l];
if (!ON_BOARD(bb)
- || board[bb] != EMPTY
+ || IS_COLOR(board[bb])
|| liberty_of_string(bb, pos))
continue;
@@ -1106,7 +1106,7 @@
int i, j;
int k;
- ASSERT1(board[str] != EMPTY, str);
+ ASSERT1(IS_COLOR(board[str]), str);
ASSERT1(stackp == 0, str);
*lunch = NO_MOVE;
@@ -1401,7 +1401,7 @@
int num_stones;
int stones[MAX_BOARD * MAX_BOARD];
gg_assert(stackp == 0);
- ASSERT1(board[pos] != EMPTY, pos);
+ ASSERT1(IS_COLOR(board[pos]), pos);
num_stones = findstones(pos, MAX_BOARD * MAX_BOARD, stones);
for (k = 0; k < num_stones; k++)
@@ -1421,7 +1421,7 @@
{
int pos;
ASSERT_ON_BOARD1(str);
- ASSERT1(worm[str].color != EMPTY, str);
+ ASSERT1(IS_COLOR(worm[str].color), str);
for (pos = BOARDMIN; pos < BOARDMAX; pos++)
if (board[pos] == board[str] && is_same_worm(pos, str))
@@ -1661,7 +1661,7 @@
*edge = 0;
- if (board[pos] != EMPTY)
+ if (IS_COLOR(board[pos]))
origin = find_origin(pos);
cavity_recurse(pos, ml, &border_color, edge, origin);
- [gnugo-devel] != EMPTY or IS_COLOR ?,
Teun Burgers <=