X-Git-Url: https://git.cworth.org/git?p=loudgame;a=blobdiff_plain;f=loa-board.h;h=9c3c466a0ef321685eaf470f7c4d8ae21ea0e592;hp=4532e01f156c2d22c67ce7549e3c3f3d437cd517;hb=HEAD;hpb=53f4e9ba973bb1f15f41ba8fdd46ce592eafd9a2 diff --git a/loa-board.h b/loa-board.h index 4532e01..9c3c466 100644 --- a/loa-board.h +++ b/loa-board.h @@ -40,6 +40,25 @@ typedef enum { LOA_CELL_EMPTY } loa_cell_t; +typedef struct { + int x1; int y1; + int x2; int y2; + loa_bool_t is_capture; +} loa_move_t; + +/* Return a string representation of a move. The return value is a + * pointer to a static buffer that will be reused from one call to the + * next. So the contents should be copied if needed. This function + * call is not thread-safe. */ +const char * +loa_move_to_string (const loa_move_t *move); + +/* Initialize an loa_move_t structure based on a string value, + * (presumably the result of loa_move_to_string). Returns TRUE if + * successful. */ +loa_bool_t +loa_move_init_from_string (loa_move_t *move, const char *string); + /* 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 @@ -58,14 +77,29 @@ typedef struct { int diag_grave_pieces[LOA_DIAG_ARRAY_SIZE]; int diag_acute_pieces[LOA_DIAG_ARRAY_SIZE]; + int num_moves; + loa_move_t *moves; + int moves_size; + loa_player_t player; } loa_board_t; -/* Initialize a board for a new game of Lines of Action. The 12 pieces +/* Initialize an loa_board_t structure. This function must be called + * before passing the board to any other loa_board function. It will + * implicitly call loa_board_reset for you. When you are finished + * using the board, you should call loa_board_fini. */ +void +loa_board_init (loa_board_t *board); + +/* Free all resources associated with a board. */ +void +loa_board_fini (loa_board_t *board); + +/* Reset 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); +loa_board_reset (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 @@ -73,17 +107,31 @@ loa_board_init (loa_board_t *board); 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 +/* Move a piece from (move->x1,move->y1) to (move->x2,move->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. + * + * After this function returns, the move->is_capture field will be set + * as appropriate whether the move is a capture or not. + */ +loa_bool_t loa_board_move (loa_board_t *board, - int x1, int y1, - int x2, int y2, + loa_move_t *move, char **error); +/* Check whether a move is legal, but without performing the move. + * + * After this function returns, the move->is_capture field will be set + * as appropriate whether the move is a capture or not. + */ +loa_bool_t +loa_board_move_is_legal (loa_board_t *board, + loa_move_t *move, + 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