summaryrefslogtreecommitdiff
path: root/ver5/ttt.h
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2016-06-01 19:41:17 -0700
committerScott Gasch <[email protected]>2016-06-01 19:41:17 -0700
commit6d38eb746e86589e3b8fa10ba37d206af5eb7ebf (patch)
tree0d84c8901ff5df4dff2386e55b454c9001d1582d /ver5/ttt.h
Initial checking of tic tac toe minimax tutorial code.
Diffstat (limited to 'ver5/ttt.h')
-rw-r--r--ver5/ttt.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/ver5/ttt.h b/ver5/ttt.h
new file mode 100644
index 0000000..bdf79a5
--- /dev/null
+++ b/ver5/ttt.h
@@ -0,0 +1,96 @@
+#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))
+#define ON_DIAGONAL_1(a, b) ((a) == (b))
+#define ON_DIAGONAL_2(a, b) ((b) == ((g_uBoardSize - a) - 1))
+#define GOOD_COORD(x) ((x) < g_uBoardSize)
+
+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;
+ SQUARE **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_ */