struct board * board_copy(struct board *b2, struct board *b1) { memcpy(b2, b1, sizeof(struct board)); size_t size = board_alloc(b2); memcpy(b2->b, b1->b, size); // XXX: Special semantics. b2->fbook = NULL; return b2; }
void board_resize(struct board *board, int size) { #ifdef BOARD_SIZE assert(board_size(board) == size + 2); #endif assert(size <= BOARD_MAX_SIZE); board->size = size + 2 /* S_OFFBOARD margin */; board->size2 = board_size(board) * board_size(board); board->bits2 = 1; while ((1 << board->bits2) < board->size2) board->bits2++; if (board->b) free(board->b); size_t asize = board_alloc(board); memset(board->b, 0, asize); }
/* static char game (char **board) { int round, i, j, l, ref; char buffer[BUFFER_SIZE]; for (round = 0; round < (m * n); round++) { i = 0; system ("clear"); printf ("Number of stone to align to win (k) = %d\n\n", k); board_print (board); do { printf ("\nPlayer '%c' give your move 'line column' (eg: 1 2)," " press 'Q' to quit:\n ", (round % 2 == 0 ? PLAYER1 : PLAYER2)); fgets (buffer, BUFFER_SIZE, stdin); clean (buffer); char *clean = strtok (buffer, ",. - "); while (clean != NULL) { if (isdigit (clean[0])) { if (l == 0) i = str2index (clean); else if (l == 0) j = str2index (clean); else printf (" Too much argument \n" "The first two parameters will be used\n"); l++; } if (isalpha (clean[0])) if (clean[0] == 'q' || clean[0] == 'Q') return (EXIT_SUCCESS); clean = strtok (NULL, " ,.-"); } if (next >= 2) ref = board_set ((round % 2 == 0 ? PLAYER1 : PLAYER2), i, j, board); else printf ("Not enought argument. Try again please.\n"); } while ((ctrl != 0) || (next < 2)); if (is_winner (board) != NONE) return (is_winner (board)); } return NONE; } */ int main (int argc, char **argv) { int optc; static struct option long_opts[] = { /* These options do not set a flag. We distinguish them by their indices. */ {"verbose", no_argument, NULL, 'v'}, {"set-m", required_argument, NULL, 'm'}, {"set-n", required_argument, NULL, 'n'}, {"set-k", required_argument, NULL, 'k'}, {"all-ai", no_argument, NULL, '0'}, {"player1-ai", no_argument, NULL, '1'}, {"player2-ai", no_argument, NULL, '2'}, {"contest", required_argument, NULL, 'c'}, {"version", no_argument, NULL, 'V'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}, }; while ((optc = getopt_long (argc, argv, "m:n:k:012c:vVh", long_opts, NULL)) != -1) { switch (optc) { case 'm': case 'n': case 'k': check_and_set (optc, atoi (optarg)); break; case '0': printf ("set both players to be an AI\n"); break; case '1': printf ("set first player as an AI\n"); break; case '2': printf ("set second player as an AI\n"); break; case 'c': printf ("enable 'contest mode'\n"); break; case 'v': verbose = true; break; case 'V': version (); break; case 'h': usage (EXIT_SUCCESS); break; default: usage (EXIT_FAILURE); } } board = board_alloc (); //char bo = game(board); board_free (board); return (EXIT_SUCCESS); }