RCS file: /sources/gnugo/gnugo/doc/board.texi,v
retrieving revision 1.15
diff -u -r1.15 board.texi
|
|
|
|
| 71 | 71 | @group |
| 72 | 72 | |
| 73 | 73 | int board_size; |
| 74 | | Intersection board[MAXSIZE]; |
| | 74 | Intersection board[BOARDSIZE]; |
| 75 | 75 | int board_ko_pos; |
| 76 | 76 | |
| 77 | 77 | float komi; |
| 78 | 78 | int white_captured; |
| 79 | 79 | int black_captured; |
| 80 | 80 | |
| 81 | | Hash_data hashdata; |
| | 81 | Hash_data board_hash; |
| 82 | 82 | @end group |
| 83 | 83 | @end example |
| 84 | 84 | |
| 85 | | The description of the @code{Position} struct is applicable to these |
| | 85 | The description of the @code{board_state} struct is applicable to these |
| 86 | 86 | variables also, so we won't duplicate it here. All these variables are |
| 87 | 87 | globals for performance reasons. Behind these variables, there are a |
| 88 | 88 | number of other private data structures. These implement incremental |
| 89 | 89 | handling of strings, liberties and other properties |
| 90 | | (@pxref{Incremental Board}). The variable @code{hashdata} contains information |
| | 90 | (@pxref{Incremental Board}). The variable @code{board_hash} contains information |
| 91 | 91 | about the hash value for the current position (@pxref{Hashing}). |
| 92 | 92 | |
| 93 | 93 | These variables should never be manipulated directly, since they are |
| … |
… |
|
| 181 | 181 | #define NS (MAX_BOARD + 1) |
| 182 | 182 | #define WE 1 |
| 183 | 183 | #define SOUTH(pos) ((pos) + NS) |
| 184 | | #define WEST(pos) ((pos) - 1) |
| | 184 | #define WEST(pos) ((pos) - WE) |
| 185 | 185 | #define NORTH(pos) ((pos) - NS) |
| 186 | | #define EAST(pos) ((pos) + 1) |
| | 186 | #define EAST(pos) ((pos) + WE) |
| 187 | 187 | @end example |
| 188 | 188 | |
| 189 | 189 | There are also shorthand macros @code{SW}, @code{NW}, @code{NE}, |
| … |
… |
|
| 209 | 209 | often one computation is sufficient for 1D-coordinate where we would need |
| 210 | 210 | two with two 2D-coordinates: If we, for example, want to have the |
| 211 | 211 | coordinate of the upper right of @code{pos}, we can do this with |
| 212 | | @code{NORTH(EAST(pos))} instead of @code{(i+1, j-1)}. |
| | 212 | @code{NE(pos)} instead of @code{(i+1, j-1)}. |
| 213 | 213 | |
| 214 | 214 | @strong{Important}: The 2D coordinate @code{(-1,-1)}, which is used for |
| 215 | 215 | pass and sometimes to indicate no point, maps to the 1D coordinate |
| … |
… |
|
| 219 | 219 | A loop over multiple directions is straightforwardly written: |
| 220 | 220 | |
| 221 | 221 | @example |
| 222 | | for (k = 0; k < 4; k++) @{ |
| | 222 | for (k = 0; k < 4; ++k) @{ |
| 223 | 223 | int d = delta[k]; |
| 224 | 224 | do_something(pos + d); |
| 225 | 225 | @} |
| … |
… |
|
| 240 | 240 | a point on the board. |
| 241 | 241 | |
| 242 | 242 | Often one wants to traverse the board, carrying out some function |
| 243 | | at every vertex. Here are two possible ways of doing this: |
| | 243 | at every vertex. There is a macro for doing this: |
| 244 | 244 | |
| 245 | 245 | @example |
| 246 | | int m, n; |
| 247 | | for (m = 0; m < board_size; m++) |
| 248 | | for (n = 0; n < board_size; n++) @{ |
| 249 | | do_something(POS(m, n)); |
| 250 | | @} |
| | 246 | #define scan_board(_pos_var, _code) |
| 251 | 247 | @end example |
| 252 | 248 | |
| 253 | | Or: |
| | 249 | The @code{_code} parameter is code to be run for each vertex and |
| | 250 | @code{_pos_var} is name of the variable, which will hold the 1D position |
| | 251 | on the board, to be used inside @code{_code}. @code{break} and |
| | 252 | @code{continue} can be used inside @code{_code} like inside @code{for} |
| | 253 | loop. @strong{Warning:} every variable |
| | 254 | declared inside @code{_code} must be declared separately or there will be |
| | 255 | compilation errors (eg. @code{int x; int y;} instead of @code{int x, y;}). |
| | 256 | Example: |
| 254 | 257 | |
| 255 | 258 | @example |
| 256 | | int pos; |
| 257 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) @{ |
| 258 | | if (ON_BOARD(pos)) |
| 259 | | do_something(pos); |
| 260 | | @} |
| | 259 | |
| | 260 | int pos; |
| | 261 | |
| | 262 | scan_board(pos, |
| | 263 | int x; |
| | 264 | int y; |
| | 265 | x = do_something_with(pos); |
| | 266 | y = do_something_else_with(pos); |
| | 267 | ) |
| | 268 | |
| 261 | 269 | @end example |
| 262 | 270 | |
| 263 | 271 | |