]> git.cworth.org Git - dvonn/blob - dvonn-board.h
Implement automatic pass (when there is no legal move) and end-of-game
[dvonn] / dvonn-board.h
1 /*
2  * Copyright (C) 2008 Carl Worth
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see http://www.gnu.org/licenses/ .
16  *
17  * Author: Carl Worth <cworth@cworth.org>
18  */
19
20 #ifndef DVONN_BOARD_H
21 #define DVONN_BOARD_H
22
23 typedef int dvonn_bool_t;
24
25 #ifndef FALSE
26 #define FALSE 0
27 #endif
28 #ifndef TRUE
29 #define TRUE  1
30 #endif
31
32 typedef enum {
33     DVONN_PLAYER_BLACK,
34     DVONN_PLAYER_WHITE
35 } dvonn_player_t;
36
37 typedef enum {
38     DVONN_CELL_BLACK = DVONN_PLAYER_BLACK,
39     DVONN_CELL_WHITE = DVONN_PLAYER_WHITE,
40     DVONN_CELL_RED,
41     DVONN_CELL_EMPTY,
42     DVONN_CELL_INVALID
43 } dvonn_cell_type_t;
44
45 typedef struct {
46     dvonn_cell_type_t type;
47     int height;
48     dvonn_bool_t contains_red;
49 } dvonn_cell_t;
50
51 #define DVONN_BOARD_X_SIZE 11
52 #define DVONN_BOARD_Y_SIZE 5
53
54 typedef enum {
55     DVONN_PHASE_PLACEMENT,
56     DVONN_PHASE_MOVEMENT,
57     DVONN_PHASE_GAME_OVER
58 } dvonn_phase_t;
59
60 typedef struct {
61     dvonn_cell_t cells[DVONN_BOARD_X_SIZE][DVONN_BOARD_Y_SIZE];
62     dvonn_phase_t phase;
63     dvonn_player_t player;
64     int moves;
65     int score[2]; /* index by dvonn_player_t */
66 } dvonn_board_t;
67
68 /* Initialize a board for a new game of DVONN. */
69 void
70 dvonn_board_init (dvonn_board_t *board);
71
72 /* Place a piece at (x,y) where (0,0) is at the upper-left corner of
73  * the board. Returns TRUE if the move is legal and is performed. If
74  * the move is not legal this function returns FALSE, no change will
75  * be performed on the board, and *error will be set to a string
76  * describing why the move is illegal.*/
77 int
78 dvonn_board_place (dvonn_board_t *board,
79                    int x, int y,
80                    char **error);
81
82 /* Move a piece from (x1,y1) to (x2,y2) where (0,0) is at the
83  * upper-left corner of the board. Returns TRUE if the move is legal
84  * and is performed. If the move is not legal this function returns
85  * FALSE, no change will be performed on the board, and *error will be
86  * set to a string describing why the move is illegal.*/
87 int
88 dvonn_board_move (dvonn_board_t *board,
89                 int x1, int y1,
90                 int x2, int y2,
91                 char **error);
92
93 /* Is the cell at (x,y) occupied by a piece. Returns FALSE for all
94  * out-of-bounds coordinates. */
95 dvonn_bool_t
96 dvonn_board_cell_occupied (dvonn_board_t *board,
97                            int x, int y);
98
99 /* Is the cell at (x,y) occupied by a piece (or stack) with the given
100  * player's piece at the top. Returns FALSE for all out-of-bounds
101  * coordinates. */
102 dvonn_bool_t
103 dvonn_board_cell_owned_by (dvonn_board_t *board,
104                            int x, int y, dvonn_player_t player);
105
106 /* Is the cell at (x,y) surrounded by other pieces, (such that it is
107  * not legal for a piece at (x,y) to move. */
108 dvonn_bool_t
109 dvonn_board_cell_surrounded (dvonn_board_t *board,
110                              int x, int y);
111
112
113 #endif