]> git.cworth.org Git - ttt/blob - src/ttt-board.c
27fb19ee939e82df9921bf173b949135b90c98b4
[ttt] / src / ttt-board.c
1 /* ttt.c - client-server tic-tac-toe game
2  *
3  * Copyright © 2005 Carl Worth
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Author: Carl Worth <cworth@cworth.org>
20  */
21
22 #include "ttt-board.h"
23
24 struct _ttt_board {
25   int cells[TTT_BOARD_MAX_CELLS];
26 };
27
28 /* Initialize an empty board. */
29 void
30 ttt_board_init (ttt_board_t *board)
31 {
32   int i;
33   for (i = 0; i < TTT_BOARD_MAX_CELLS; i++)
34     {
35       board->cells[i] = 0;
36     }
37 }
38
39 /* Initialize a board from its string representation.
40  *
41  * Returns: TTT_BOARD_SUCCESS or TTT_BOARD_INVALID_BOARD if the board
42  * string could not be properly parsed.
43  */
44 void
45 ttt_board_init_from_string (ttt_board_t *board,
46                             const char  *s)
47 {
48     /* XXX: NYI */
49 }
50
51 /* Return the string representation of a board.
52  *
53  * The return value is a malloc()ed string that should be free()ed
54  * when no longer needed.
55  *
56  * Errors: If out-of-memory occurs, this function will not return.
57  */
58 char *
59 ttt_board_to_string (ttt_board_t *board)
60 {
61     /* XXX: NYI */
62     return NULL;
63 }
64
65 /* Write a string representation of a board to the provided file.
66  *
67  * Errors: If out-of-memory or a file IO error occurs, this function
68  * will not return.
69  */
70 void
71 ttt_board_write (ttt_board_t *board, FILE *file)
72 {
73     char *s;
74
75     s = ttt_board_to_string (board);
76
77     xfwrite (s, 1, strlen (s) + 1, file);
78
79     free (s);
80 }
81