]> git.cworth.org Git - ttt/commitdiff
2005-11-28 Kevin Worth <kevin@theworths.org>
authorKevin Worth <kevin@theworths.org>
Mon, 28 Nov 2005 18:51:44 +0000 (18:51 +0000)
committerKevin Worth <kevin@theworths.org>
Mon, 28 Nov 2005 18:51:44 +0000 (18:51 +0000)
        * 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.

ChangeLog
PROTOCOL
src/Makefile.am
src/test-board.c [new file with mode: 0644]
src/ttt-board.c
src/ttt-board.h

index d1a6ced9d6417665bc6849c6de8e6b9f855a6808..3e627443e50a169a81d3d1326a312b25b45789b2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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:
index 519b1bab79dca6e820428ae48ac787b903bf77c6..c507ffeb27ca47eaa9c9098c301486b22916ffd3 100644 (file)
--- a/PROTOCOL
+++ b/PROTOCOL
@@ -173,9 +173,9 @@ Document Conventions
        <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
     
index c205ef940b4dfe060674cca5dcf5483c666227cb..1d5de3f7669f20af0daa85e2f09edf2e73266f81 100644 (file)
@@ -1,4 +1,5 @@
 bin_PROGRAMS = ttt-server ttt-client
+noinst_PROGRAMS = test-board
 
 ttt_common_sources =           \
        ttt-args.c              \
@@ -22,7 +23,13 @@ ttt_server_SOURCES =                 \
        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)
+
diff --git a/src/test-board.c b/src/test-board.c
new file mode 100644 (file)
index 0000000..d36b36d
--- /dev/null
@@ -0,0 +1,17 @@
+/* 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;
+}
index 27fb19ee939e82df9921bf173b949135b90c98b4..dd068b5850285110f84e5436f2fa99c960b2910d 100644 (file)
 
 #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;
     }
 }
 
@@ -58,8 +54,15 @@ ttt_board_init_from_string (ttt_board_t *board,
 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.
index e9498ccca87cfc4b4d7e08bd1f90b9a1e4c4d8df..b04d4b3870116240421ab23dec08b9c7b38aec1e 100644 (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);