[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnugo-devel] NUM_STONES macro instead of num_stones
From: |
Teun Burgers |
Subject: |
[gnugo-devel] NUM_STONES macro instead of num_stones |
Date: |
Thu, 24 Apr 2003 22:24:11 +0200 |
In order to make sure array bounds checking can be
performed on the real_num_stones array, I propose
to use a macro to implement the offset rather than
the num_stones pointer.
See the attached p3319_01.txt
Teun
Index: matchpat.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/matchpat.c,v
retrieving revision 1.54
diff -u -r1.54 matchpat.c
--- matchpat.c 4 Mar 2003 23:27:53 -0000 1.54
+++ matchpat.c 24 Apr 2003 20:20:58 -0000
@@ -1257,6 +1257,7 @@
*/
static int real_num_stones[2*BOARDMAX];
static int *const num_stones = real_num_stones + BOARDMAX;
+#define NUM_STONES(a) real_num_stones[(a) + BOARDMAX]
/* Stone locations are stored in this array. They might be needed by callback
* function.
@@ -1284,7 +1285,7 @@
int second_corner
= AFFINE_TRANSFORM(pattern->second_corner_offset, trans, anchor);
- if (num_stones[second_corner] == stones
+ if (NUM_STONES(second_corner) == stones
&& (!pattern->symmetric || trans < 4)) {
/* We have found a matching pattern. */
ASSERT1(board[move] == EMPTY, move);
@@ -1294,7 +1295,7 @@
}
if (variation->num_variations
- && num_stones[move] == variation->num_stones
+ && NUM_STONES(move) == variation->num_stones
&& board[move] == color_check) {
/* A matching variation. */
pattern_stones[stones] = move;
@@ -1329,21 +1330,21 @@
/* Fill in the num_stones[] array. We use `max_width' and `max_height'
* fields of database structure to stop working as early as possible.
*/
- num_stones[anchor] = IS_STONE(board[anchor]);
+ NUM_STONES(anchor) = IS_STONE(board[anchor]);
pos = anchor;
for (i = 1; i < database->max_height; i++) {
pos += dx;
if (!ON_BOARD(pos)) {
do {
- num_stones[pos] = BOARDMAX;
+ NUM_STONES(pos) = BOARDMAX;
pos += dx;
} while (++i < database->max_height);
break;
}
- num_stones[pos] = num_stones[pos - dx] + IS_STONE(board[pos]);
+ NUM_STONES(pos) = NUM_STONES(pos - dx) + IS_STONE(board[pos]);
}
pos = anchor;
@@ -1351,24 +1352,24 @@
pos += dy;
if (!ON_BOARD(pos)) {
do {
- num_stones[pos] = BOARDMAX;
+ NUM_STONES(pos) = BOARDMAX;
pos += dy;
} while (++j < database->max_width);
break;
}
- num_stones[pos] = num_stones[pos - dy] + IS_STONE(board[pos]);
+ NUM_STONES(pos) = NUM_STONES(pos - dy) + IS_STONE(board[pos]);
}
for (i = 1; i < database->max_height; i++) {
pos = anchor + i * dy;
for (j = 1; j < database->max_width; j++) {
pos += dx;
- num_stones[pos] = num_stones[pos - dx] + num_stones[pos - dy]
- - num_stones[pos - dx - dy];
+ NUM_STONES(pos) = NUM_STONES(pos - dx) + NUM_STONES(pos - dy)
+ - NUM_STONES(pos - dx - dy);
if (ON_BOARD1(pos) && IS_STONE(board[pos]))
- num_stones[pos]++;
+ NUM_STONES(pos)++;
}
}
@@ -1378,7 +1379,7 @@
for (i = 0; i < database->num_top_variations; i++) {
int move = AFFINE_TRANSFORM(variation->move_offset, k, anchor);
- if (num_stones[move] == 1 && IS_STONE(board[move])) {
+ if (NUM_STONES(move) == 1 && IS_STONE(board[move])) {
pattern_stones[0] = move;
do_corner_matchpat(variation->num_variations, variation->variations,
board[move], callback, color, k, anchor, 1);
- [gnugo-devel] NUM_STONES macro instead of num_stones,
Teun Burgers <=