2 * Copyright (C) 2008 Carl Worth
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.
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.
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/ .
17 * Author: Carl Worth <cworth@cworth.org>
23 typedef int loa_bool_t;
38 LOA_CELL_BLACK = LOA_PLAYER_BLACK,
39 LOA_CELL_WHITE = LOA_PLAYER_WHITE,
46 loa_bool_t is_capture;
49 /* Return a string representation of a move. The return value is a
50 * pointer to a static buffer that will be reused from one call to the
51 * next. So the contents should be copied if needed. This function
52 * call is not thread-safe. */
54 loa_move_to_string (const loa_move_t *move);
56 /* Initialize an loa_move_t structure based on a string value,
57 * (presumably the result of loa_move_to_string). Returns TRUE if
60 loa_move_init_from_string (loa_move_t *move, const char *string);
62 /* The implementation of board_group_size depends on the square of
63 * BOARD_SIZE being less than or equal to 64. */
64 #define LOA_BOARD_SIZE 8
65 #define LOA_DIAG_ARRAY_SIZE (2 * LOA_BOARD_SIZE - 1)
68 loa_cell_t cells[LOA_BOARD_SIZE][LOA_BOARD_SIZE];
70 /* Number of black and white pieces */
73 /* Number of pieces (of either color) in each row, column, and
75 int row_pieces[LOA_BOARD_SIZE];
76 int col_pieces[LOA_BOARD_SIZE];
77 int diag_grave_pieces[LOA_DIAG_ARRAY_SIZE];
78 int diag_acute_pieces[LOA_DIAG_ARRAY_SIZE];
87 /* Initialize an loa_board_t structure. This function must be called
88 * before passing the board to any other loa_board function. It will
89 * implicitly call loa_board_reset for you. When you are finished
90 * using the board, you should call loa_board_fini. */
92 loa_board_init (loa_board_t *board);
94 /* Free all resources associated with a board. */
96 loa_board_fini (loa_board_t *board);
98 /* Reset board for a new game of Lines of Action. The 12 pieces
99 * for black and white will be put in their initial places and black
100 * will be set as the current player. */
102 loa_board_reset (loa_board_t *board);
104 /* Does the square at (x,y) belong to a winning group? That is, is
105 * there a piece at (x,y) that is 8-way connected to all pieces on the
106 * board of the same color. */
108 loa_board_is_won (loa_board_t *board, int x, int y);
110 /* Move a piece from (move->x1,move->y1) to (move->x2,move->y2) where
111 * (0,0) is at the upper-left corner of the board. Returns TRUE if the
112 * move is legal and is performed. If the move is not legal this
113 * function returns FALSE, no change will be performed on the board,
114 * and *error will be set to a string describing why the move is
117 * After this function returns, the move->is_capture field will be set
118 * as appropriate whether the move is a capture or not.
121 loa_board_move (loa_board_t *board,
125 /* Check whether a move is legal, but without performing the move.
127 * After this function returns, the move->is_capture field will be set
128 * as appropriate whether the move is a capture or not.
131 loa_board_move_is_legal (loa_board_t *board,
135 /* Execute a 'pass'---changing the player-to-move from the current
136 * player to the opponent. Returns TRUE if the pass is executed. Will
137 * eventually return FALSE if the current player has a legal move that
138 * could be made, but this is not yet implemented.
141 loa_board_pass (loa_board_t *board);
143 /* Allocate a new string showing the state of the current board.
144 * When finsihed, the called should free() the resulting value.
147 loa_board_to_string (loa_board_t *board);