]> git.cworth.org Git - loa/blobdiff - loa-board.h
Add drawing of pieces (along with loa-board board-management code from loudgame)
[loa] / loa-board.h
diff --git a/loa-board.h b/loa-board.h
new file mode 100644 (file)
index 0000000..4532e01
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2008 Carl Worth
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ * Author: Carl Worth <cworth@cworth.org>
+ */
+
+#ifndef LOA_BOARD_H
+#define LOA_BOARD_H
+
+typedef int loa_bool_t;
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+#ifndef TRUE
+#define TRUE  1
+#endif
+
+typedef enum {
+    LOA_PLAYER_BLACK,
+    LOA_PLAYER_WHITE
+} loa_player_t;
+
+typedef enum {
+    LOA_CELL_BLACK = LOA_PLAYER_BLACK,
+    LOA_CELL_WHITE = LOA_PLAYER_WHITE,
+    LOA_CELL_EMPTY
+} loa_cell_t;
+
+/* The implementation of board_group_size depends on the square of
+ * BOARD_SIZE being less than or equal to 64. */
+#define LOA_BOARD_SIZE 8
+#define LOA_DIAG_ARRAY_SIZE (2 * LOA_BOARD_SIZE - 1)
+
+typedef struct {
+    loa_cell_t cells[LOA_BOARD_SIZE][LOA_BOARD_SIZE];
+
+    /* Number of black and white pieces */
+    int num_pieces[2];
+
+    /* Number of pieces (of either color) in each row, column, and
+     * diagonal. */
+    int row_pieces[LOA_BOARD_SIZE];
+    int col_pieces[LOA_BOARD_SIZE];
+    int diag_grave_pieces[LOA_DIAG_ARRAY_SIZE];
+    int diag_acute_pieces[LOA_DIAG_ARRAY_SIZE];
+
+    loa_player_t player;
+} loa_board_t;
+
+/* Initialize a board for a new game of Lines of Action. The 12 pieces
+ * for black and white will be put in their initial places and black
+ * will be set as the current player. */
+void
+loa_board_init (loa_board_t *board);
+
+/* Does the square at (x,y) belong to a winning group? That is, is
+ * there a piece at (x,y) that is 8-way connected to all pieces on the
+ * board of the same color. */
+int
+loa_board_is_won (loa_board_t *board, int x, int y);
+
+/* 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
+ * FALSE, no change will be performed on the board, and *error will be
+ * set to a string describing why the move is illegal.*/
+int
+loa_board_move (loa_board_t *board,
+               int x1, int y1,
+               int x2, int y2,
+               char **error);
+
+/* Execute a 'pass'---changing the player-to-move from the current
+ * player to the opponent. Returns TRUE if the pass is executed.  Will
+ * eventually return FALSE if the current player has a legal move that
+ * could be made, but this is not yet implemented.
+ */
+int
+loa_board_pass (loa_board_t *board);
+
+/* Allocate a new string showing the state of the current board.
+ * When finsihed, the called should free() the resulting value.
+ */
+char *
+loa_board_to_string (loa_board_t *board);
+
+#endif