summaryrefslogtreecommitdiff
path: root/ver4/ttt.h
blob: 6ddee35ac8b57a2bd7542932cdf811c4388c2715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef TTT_H_
#define TTT_H_

#define ALPHA_BETA_SEARCH 1

#define TRUE (1)
#define FALSE (0)

#define IN
#define OUT

typedef unsigned int BOOL;

//
// Constants for each state a board square can be in and a programmer
// defined type for these states.
//
#define X_MARK (-1)
#define EMPTY  (0)
#define O_MARK (+1)
#define TIE    (+2)
#define OPPOSITE_MARK(m) ((m) * -1)
#define X_OR_O(m) (((m) == X_MARK) || \
                   ((m) == O_MARK))

typedef signed char SQUARE;
#define IS_SQUARE_EMPTY(x) (x == EMPTY)

//
// A (simple) representation of a tic tac toe position
//
typedef struct _POSITION
{
    SQUARE sWhoseTurn;
    int **sBoard;
    //SQUARE sBoard[BOARD_SIZE][BOARD_SIZE];
    int *iVSums;
    //int iVSums[BOARD_SIZE];
    int *iHSums;
    //int iHSums[BOARD_SIZE];
    int iDSums[2];
    unsigned int uNumEmpty;
} POSITION;

#define NUM_TO_HPOS(x)   ((x) % g_uBoardSize)
#define NUM_TO_VPOS(x)   ((x) / g_uBoardSize)
#define VALID_SUM(x)     (abs(x) <= g_uBoardSize)

//
// A representation of a move in a tic tac toe game
//
typedef unsigned int COORD;

typedef struct _MOVE
{
    COORD cHpos;
    COORD cVpos;
    SQUARE sMark;
} MOVE;

//
// Score values
//
#define INFINITY (+100)
#define DRAWSCORE (0)

//
// An assert mechanism
//
#ifdef DEBUG
#define ASSERT(x)       if (x)    \
                        { ; }     \
                        else      \
                        { (void) _assert(__FILE__, __LINE__); }
#else
#define ASSERT(x)       ;
#endif /* DEBUG */

 
void
_assert(char *sz, unsigned int i)
{
    fprintf(stderr, "Assertion failed in %s at line %u.\n", sz, i);
#if defined(WIN32)
	__asm int 3;
#elif defined(__unix__)
    asm("int3\n");
#else
    #error foo
#endif
}

#endif /* TTT_H_ */