]> git.cworth.org Git - ttt/blobdiff - src/ttt-board.c
2005-11-28 Kevin Worth <kevin@theworths.org>
[ttt] / src / ttt-board.c
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.