typedef unsigned int size_t; extern void *malloc (size_t __size); typedef char bool; typedef struct _Board { struct _Board *(*copy) (const struct _Board *); void (*setup) (struct _Board *, int, int, int); void (*display) (struct _Board *); int (*eval) (struct _Board *); void (*score) (struct _Board *, int *, int *); bool (*full) (struct _Board *); int (*winner) (struct _Board *); bool (*valid_move) (struct _Board *, int); bool (*move) (struct _Board *, int, int); void (*unmove) (struct _Board *); int (*getmove) (struct _Board *, int, int *, int *); void (*help) (void); char (*symbol) (struct _Board *, int, int); void (*coords) (struct _Board *, int, char *); int rows, cols; int squares; int *moves; int nummoves; int X_player; int *board; int **points; int numpoints; int depth, depth2; int *center; } Board; Board *c4_copy (const Board *); void c4_setup (Board *, int, int, int); void c4_display (Board *); int c4_eval (Board *); inline bool c4_full (Board *); int c4_winner (Board *); bool c4_valid_move (Board *, int); bool c4_move (Board *, int, int); void c4_unmove (Board *); int c4_getmove (Board *, int, int *, int *); void c4_help (void); char c4_symbol (Board *, int, int); void c4_coords (Board *, int, char *); Board *c4_new (int players, int size, int depth) { Board *T = (Board *) malloc (sizeof (Board)); Board *B = (Board *)T; int **points; int *board; int i, j, point = 0; int MyPE = 0; int rows, cols; B->copy = c4_copy; B->setup = c4_setup; B->display = c4_display; B->eval = c4_eval; B->full = c4_full; B->winner = c4_winner; B->valid_move = c4_valid_move; B->move = c4_move; B->unmove = c4_unmove; B->getmove = c4_getmove; B->help = c4_help; B->symbol = c4_symbol; B->coords = c4_coords; B->score = ((void *)0) ; rows = B->rows = 6; cols = B->cols = 7; B->squares = 7; if (MyPE == 0) c4_setup ((Board *)T, players, depth, 0); B->board = (int *) malloc (rows*cols * sizeof(int)); B->moves = (int *) malloc (rows*cols * sizeof(int)); B->nummoves = 0; for (i = 0; i < rows*cols; i++) B->board[i] = B->moves[i] = 0; B->numpoints = rows*(cols-3) + cols*(rows-3) + 2*(rows-3)*(cols-3); points = (int **) malloc (B->numpoints * 4 * sizeof(int *)); board = B->board; for (j = 0; j < rows - 3; j++) { for (i = 0; i < cols; i++, point++) { points[point*4+0] = board + i*rows + 0 + j; points[point*4+1] = board + i*rows + 1 + j; points[point*4+2] = board + i*rows + 2 + j; points[point*4+3] = board + i*rows + 3 + j; } } for (j = 0; j < cols - 3; j++) { for (i = 0; i < rows; i++, point++) { points[point*4+0] = board + i + 0*rows + j*rows; points[point*4+1] = board + i + 1*rows + j*rows; points[point*4+2] = board + i + 2*rows + j*rows; points[point*4+3] = board + i + 3*rows + j*rows; } } for (j = 0; j < cols - 3; j++) { for (i = 0; i < rows - 3; i++, point++) { points[point*4+0] = board + j*rows + i + 0*rows + 0; points[point*4+1] = board + j*rows + i + 1*rows + 1; points[point*4+2] = board + j*rows + i + 2*rows + 2; points[point*4+3] = board + j*rows + i + 3*rows + 3; } } for (j = 0; j < cols - 3; j++) { for (i = 0; i < rows - 3; i++, point++) { points[point*4+0] = board + j*rows + i + 0*rows + 3; points[point*4+1] = board + j*rows + i + 1*rows + 2; points[point*4+2] = board + j*rows + i + 2*rows + 1; points[point*4+3] = board + j*rows + i + 3*rows + 0; } } B->points = points; return T; }