1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007-2009 Joshua Simmons <mud at majidejima dot com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 #include "goban.h" /* for LCD_BOARD_SIZE */
34 #define OTHER(color) (color == BLACK ? WHITE : BLACK)
36 /* MAX_BOARD_SIZE no longer dependent on screen
37 size since zooming was implemented */
38 #define MAX_BOARD_SIZE 19
39 #define MIN_BOARD_SIZE 1
41 #define INVALID_POS ((unsigned short) -5003)
42 #define PASS_POS ((unsigned short) -5002)
44 #define POS(i, j) ((i + 1) + (j + 1) * (MAX_BOARD_SIZE + 2))
45 #define WEST(i) (i - 1)
46 #define EAST(i) (i + 1)
47 #define NORTH(i) (i - (MAX_BOARD_SIZE + 2))
48 #define SOUTH(i) (i + (MAX_BOARD_SIZE + 2))
50 unsigned short WRAP (unsigned short pos
);
52 #define I(pos) (pos % (MAX_BOARD_SIZE + 2) - 1)
53 #define J(pos) (pos / (MAX_BOARD_SIZE + 2) - 1)
55 /* Clear the data from the board, including marks and such. Should be
56 called after setting the board size */
57 void clear_board (void);
59 /* Set the size of the board. Follow with a call to clear_board() and a
60 call to setup_display(). Returns false on failure (generally, invalid
62 bool set_size_board (int width
, int height
);
64 /* Returns true if the given move is legal. allow_suicide should be true
65 if suicide is a valid move with the current ruleset */
66 bool legal_move_board (unsigned short pos
, unsigned char color
,
69 /* Returns true if the pos is on the board */
70 bool on_board (unsigned short pos
);
72 /* Get the color on the board at the given pos. Should be
73 BLACK/WHITE/EMPTY, and sometimes INVALID. */
74 unsigned char get_point_board (unsigned short pos
);
76 /* Set the color of point at pos, which must be on the board */
77 void set_point_board (unsigned short pos
, unsigned char color
);
79 /* Get the number of liberties of the group of which pos is a stone.
80 Returns less than zero if pos is empty. If the number of liberties of
81 the group is greater than 2, 2 is returned. */
82 int get_liberties_board (unsigned short pos
);
84 /* A simple flood fill algorithm for capturing or uncapturing stones.
85 Returns the number of locations changed. */
86 int flood_fill_board (unsigned short pos
, unsigned char color
);
88 /* The size of the board */
89 extern unsigned int board_width
;
90 extern unsigned int board_height
;
92 /* The number of captures for each player */
93 extern int black_captures
;
94 extern int white_captures
;
96 /* If there is a ko which cannot be retaken, this is set to the point
97 which may not be played at. Otherwise this is INVALID_POS. */
98 extern unsigned short ko_pos
;