]> git.cworth.org Git - dvonn/blobdiff - dvonn-board.h
Implement automatic pass (when there is no legal move) and end-of-game
[dvonn] / dvonn-board.h
index c1c82707c180904fd7a96387a86fbc27716a2b1c..a150b2541f7fdc5fe9566fded72662d6bec196d0 100644 (file)
@@ -37,6 +37,7 @@ typedef enum {
 typedef enum {
     DVONN_CELL_BLACK = DVONN_PLAYER_BLACK,
     DVONN_CELL_WHITE = DVONN_PLAYER_WHITE,
+    DVONN_CELL_RED,
     DVONN_CELL_EMPTY,
     DVONN_CELL_INVALID
 } dvonn_cell_type_t;
@@ -44,21 +45,40 @@ typedef enum {
 typedef struct {
     dvonn_cell_type_t type;
     int height;
+    dvonn_bool_t contains_red;
 } dvonn_cell_t;
 
 #define DVONN_BOARD_X_SIZE 11
 #define DVONN_BOARD_Y_SIZE 5
 
+typedef enum {
+    DVONN_PHASE_PLACEMENT,
+    DVONN_PHASE_MOVEMENT,
+    DVONN_PHASE_GAME_OVER
+} dvonn_phase_t;
+
 typedef struct {
     dvonn_cell_t cells[DVONN_BOARD_X_SIZE][DVONN_BOARD_Y_SIZE];
-
+    dvonn_phase_t phase;
     dvonn_player_t player;
+    int moves;
+    int score[2]; /* index by dvonn_player_t */
 } dvonn_board_t;
 
 /* Initialize a board for a new game of DVONN. */
 void
 dvonn_board_init (dvonn_board_t *board);
 
+/* Place a piece at (x,y) where (0,0) is at the upper-left corner of
+ * the board. Returns TRUE if the move is legal and is performed. If
+ * the move is not legal this function returns FALSE, no change will
+ * be performed on the board, and *error will be set to a string
+ * describing why the move is illegal.*/
+int
+dvonn_board_place (dvonn_board_t *board,
+                  int x, int y,
+                  char **error);
+
 /* Move a piece from (x1,y1) to (x2,y2) where (0,0) is at the
  * upper-left corner of the board. Returns TRUE if the move is legal
  * and is performed. If the move is not legal this function returns
@@ -70,4 +90,24 @@ dvonn_board_move (dvonn_board_t *board,
                int x2, int y2,
                char **error);
 
+/* Is the cell at (x,y) occupied by a piece. Returns FALSE for all
+ * out-of-bounds coordinates. */
+dvonn_bool_t
+dvonn_board_cell_occupied (dvonn_board_t *board,
+                          int x, int y);
+
+/* Is the cell at (x,y) occupied by a piece (or stack) with the given
+ * player's piece at the top. Returns FALSE for all out-of-bounds
+ * coordinates. */
+dvonn_bool_t
+dvonn_board_cell_owned_by (dvonn_board_t *board,
+                          int x, int y, dvonn_player_t player);
+
+/* Is the cell at (x,y) surrounded by other pieces, (such that it is
+ * not legal for a piece at (x,y) to move. */
+dvonn_bool_t
+dvonn_board_cell_surrounded (dvonn_board_t *board,
+                            int x, int y);
+
+
 #endif