summaryrefslogtreecommitdiff
path: root/apps/plugins/goban/board.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/goban/board.h')
-rw-r--r--apps/plugins/goban/board.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/apps/plugins/goban/board.h b/apps/plugins/goban/board.h
new file mode 100644
index 0000000000..cd6f01e79a
--- /dev/null
+++ b/apps/plugins/goban/board.h
@@ -0,0 +1,100 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007-2009 Joshua Simmons <mud at majidejima dot com>
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef GOBAN_BOARD_H
23#define GOBAN_BOARD_H
24
25#include "types.h"
26#include "goban.h" /* for LCD_BOARD_SIZE */
27
28#define WHITE 1
29#define BLACK 2
30#define EMPTY 0
31#define NONE 0
32#define INVALID 4
33
34#define OTHER(color) (color == BLACK ? WHITE : BLACK)
35
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
40
41#define INVALID_POS ((unsigned short) -5003)
42#define PASS_POS ((unsigned short) -5002)
43
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))
49
50unsigned short WRAP (unsigned short pos);
51
52#define I(pos) (pos % (MAX_BOARD_SIZE + 2) - 1)
53#define J(pos) (pos / (MAX_BOARD_SIZE + 2) - 1)
54
55/* Clear the data from the board, including marks and such. Should be
56 called after setting the board size */
57void clear_board (void);
58
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
61 width or height) */
62bool set_size_board (int width, int height);
63
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 */
66bool legal_move_board (unsigned short pos, unsigned char color,
67 bool allow_suicide);
68
69/* Returns true if the pos is on the board */
70bool on_board (unsigned short pos);
71
72/* Get the color on the board at the given pos. Should be
73 BLACK/WHITE/EMPTY, and sometimes INVALID. */
74unsigned char get_point_board (unsigned short pos);
75
76/* Set the color of point at pos, which must be on the board */
77void set_point_board (unsigned short pos, unsigned char color);
78
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. */
82int get_liberties_board (unsigned short pos);
83
84/* A simple flood fill algorithm for capturing or uncapturing stones.
85 Returns the number of locations changed. */
86int flood_fill_board (unsigned short pos, unsigned char color);
87
88/* The size of the board */
89extern unsigned int board_width;
90extern unsigned int board_height;
91
92/* The number of captures for each player */
93extern int black_captures;
94extern int white_captures;
95
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. */
98extern unsigned short ko_pos;
99
100#endif