+2005-11-28 Kevin Worth <kevin@theworths.org>
+
+ * PROTOCOL: Changed board cell numbering to start with zero
+ instead of one.
+
+ * src/Makefile.am:
+ * src/test-board.c: (main): Added new file for testing.
+
+ * src/ttt-board.c: (ttt_board_init), (ttt_board_to_string):
+ * src/ttt-board.h: Implemented board_to_string.
+
2005-11-28 kevin worth <kevin@theworths.org>
* src/ttt-board.c:
<number> indicates a number in the tic-tac-toe grid as
follows:
- 1|2|3
- 4|5|6
- 7|8|9
+ 0|1|2
+ 3|4|5
+ 6|7|8
Possible errors: NOTINGAME, NOTYOURMOVE, NOTGRID
bin_PROGRAMS = ttt-server ttt-client
+noinst_PROGRAMS = test-board
ttt_common_sources = \
ttt-args.c \
ttt-client.c \
ttt-server.c
+test_board_SOURCES = \
+ $(ttt_common_sources) \
+ test-board.c
+
AM_CFLAGS = $(WARN_CFLAGS) $(TTT_CFLAGS)
AM_LFLAGS = --header-file=ttt-lex.h -Cr
ttt_client_LDFLAGS = $(TTT_LIBS)
ttt_server_LDFLAGS = $(TTT_LIBS) -lpthread
+test_board_LDFLAGS = $(TTT_LIBS)
+
--- /dev/null
+/* Test ttt-board.c */
+
+#include "ttt-board.h"
+
+int
+main (void)
+{
+ ttt_board_t board;
+
+ ttt_board_init (&board);
+
+ printf ("This is the board \"");
+ ttt_board_write (&board, stdout);
+ printf ("\"\n");
+
+ return 0;
+}
#include "ttt-board.h"
-struct _ttt_board {
- int cells[TTT_BOARD_MAX_CELLS];
-};
-
/* Initialize an empty board. */
void
ttt_board_init (ttt_board_t *board)
{
- int i;
- for (i = 0; i < TTT_BOARD_MAX_CELLS; i++)
+ int i;
+ for (i = 0; i < TTT_BOARD_MAX_CELLS; i++)
{
- board->cells[i] = 0;
+ board->cells[i] = TTT_CELL_EMPTY;
}
}
char *
ttt_board_to_string (ttt_board_t *board)
{
- /* XXX: NYI */
- return NULL;
+ char *s;
+ xasprintf (&s, "\r\n"
+ "%c|%c|%c\r\n"
+ "%c|%c|%c\r\n"
+ "%c|%c|%c",
+ board->cells[0], board->cells[1], board->cells[2],
+ board->cells[3], board->cells[4], board->cells[5],
+ board->cells[6], board->cells[7], board->cells[8]);
+ return s;
}
/* Write a string representation of a board to the provided file.
#define TTT_BOARD_MAX_CELLS 9
-typedef struct _ttt_board ttt_board_t;
+typedef enum {
+ TTT_CELL_EMPTY = '_',
+ TTT_CELL_X = 'X',
+ TTT_CELL_O = 'O'
+} ttt_cell_t;
+
+typedef struct _ttt_board {
+ ttt_cell_t cells[TTT_BOARD_MAX_CELLS];
+} ttt_board_t;
void
ttt_board_init (ttt_board_t *board);