Remove more CRs.
[ttt.git] / ver5 / ttt.h
1 #ifndef TTT_H_
2 #define TTT_H_
3
4 #define ALPHA_BETA_SEARCH 1
5
6 #define TRUE (1)
7 #define FALSE (0)
8
9 #define IN
10 #define OUT
11
12 typedef unsigned int BOOL;
13
14 //
15 // Constants for each state a board square can be in and a programmer
16 // defined type for these states.
17 //
18 #define X_MARK (-1)
19 #define EMPTY  (0)
20 #define O_MARK (+1)
21 #define TIE    (+2)
22 #define OPPOSITE_MARK(m) ((m) * -1)
23 #define X_OR_O(m) (((m) == X_MARK) || \
24                    ((m) == O_MARK))
25 #define ON_DIAGONAL_1(a, b) ((a) == (b))
26 #define ON_DIAGONAL_2(a, b) ((b) == ((g_uBoardSize - a) - 1))
27 #define GOOD_COORD(x)       ((x) < g_uBoardSize)
28
29 typedef signed char SQUARE;
30 #define IS_SQUARE_EMPTY(x) (x == EMPTY)
31
32 //
33 // A (simple) representation of a tic tac toe position
34 //
35 typedef struct _POSITION
36 {
37     SQUARE sWhoseTurn;
38     SQUARE **sBoard;
39     //SQUARE sBoard[BOARD_SIZE][BOARD_SIZE];
40     int *iVSums;
41     //int iVSums[BOARD_SIZE];
42     int *iHSums;
43     //int iHSums[BOARD_SIZE];
44     int iDSums[2];
45     unsigned int uNumEmpty;
46 } POSITION;
47
48 #define NUM_TO_HPOS(x)   ((x) % g_uBoardSize)
49 #define NUM_TO_VPOS(x)   ((x) / g_uBoardSize)
50 #define VALID_SUM(x)     (abs(x) <= g_uBoardSize)
51
52 //
53 // A representation of a move in a tic tac toe game
54 //
55 typedef unsigned int COORD;
56
57 typedef struct _MOVE
58 {
59     COORD cHpos;
60     COORD cVpos;
61     SQUARE sMark;
62 } MOVE;
63
64 //
65 // Score values
66 //
67 #define INFINITY (+100)
68 #define DRAWSCORE (0)
69
70 //
71 // An assert mechanism
72 //
73 #ifdef DEBUG
74 #define ASSERT(x)       if (x)    \
75                         { ; }     \
76                         else      \
77                         { (void) _assert(__FILE__, __LINE__); }
78 #else
79 #define ASSERT(x)       ;
80 #endif /* DEBUG */
81
82  
83 void
84 _assert(char *sz, unsigned int i)
85 {
86     fprintf(stderr, "Assertion failed in %s at line %u.\n", sz, i);
87 #if defined(WIN32)
88         __asm int 3;
89 #elif defined(__unix__)
90     asm("int3\n");
91 #else
92     #error foo
93 #endif
94 }
95
96 #endif /* TTT_H_ */