]> git.cworth.org Git - ttt/blob - src/test-board.c
Beautified _board_is_won and test_board.c now quits out when won
[ttt] / src / test-board.c
1 /* Test ttt-board.c */
2
3 #include "ttt-board.h"
4
5 ttt_cell_t ttt_test_board_is_won (ttt_board_t *board);
6
7 int
8 main (void)
9 {
10     ttt_board_t board;
11     int m, i, newline;
12
13     ttt_board_init (&board);
14     
15     for (i = 0; i <= 8; i++)
16     {
17         printf ("This is the board \"");
18         ttt_board_write (&board, stdout);
19         printf ("\"\n");    
20
21         printf ("Make a move \n");
22         m = getchar();
23         newline = getchar();
24         printf ("getchar returned a numeric value of %d which is character '%c'\n", m, m);
25         m = m - '0';
26         ttt_board_make_move (&board, m);
27         ttt_board_is_won (&board);
28         if (ttt_board_is_won (&board) == TTT_CELL_X)
29         {
30             printf ("X's Win! ");
31             break;
32         }
33         else if (ttt_board_is_won (&board) == TTT_CELL_O)
34         {
35             printf ("O's Win! ");
36             break;
37         }
38     }
39
40     printf ("This is the board \"");
41     ttt_board_write (&board, stdout);
42     printf ("\"\n");    
43
44
45     return 0;
46 }