/* Start playing using the Go Text Protocol. */ void play_gtp(FILE * gtp_input, FILE * gtp_output, FILE * gtp_dump_commands, Game * g) { setbuf(gtp_output, NULL); game = g; /* Inform the GTP utility functions about the board size. */ gtp_internal_set_boardsize(game->get_boardsize()); gtp_main_loop(commands, gtp_input, gtp_output, gtp_dump_commands); }
static int gtp_boardsize(char *s) { int boardsize; if (sscanf(s, "%d", &boardsize) < 1) return gtp_failure("boardsize not an integer"); if (boardsize < MIN_BOARD || boardsize > MAX_BOARD) return gtp_failure("unacceptable size"); board_size = boardsize; gtp_internal_set_boardsize(boardsize); init_brown(); return gtp_success(""); }
/* Function: Set the board size to NxN and clear the board. * Arguments: integer * Fails: board size outside engine's limits * Returns: nothing * * Status: GTP version 2 standard command. */ static int gtp_set_boardsize(char *s) { int boardsize; if (sscanf(s, "%d", &boardsize) < 1) return gtp_failure("boardsize not an integer"); if (boardsize <= 0 || boardsize > MAX_BOARD) { if (GTP_VERSION == 1) return gtp_failure("unacceptable boardsize"); else return gtp_failure("unacceptable size"); } game->set_boardsize(boardsize); game->clear_board(); gtp_internal_set_boardsize(boardsize); return gtp_success(""); }
int main(int argc, char **argv) { unsigned int random_seed = 1; /* Optionally a random seed can be passed as an argument to the program. */ if (argc > 1) sscanf(argv[1], "%u", &random_seed); srand(random_seed); /* Make sure that stdout is not block buffered. */ setbuf(stdout, NULL); /* Inform the GTP utility functions about the initial board size. */ gtp_internal_set_boardsize(board_size); /* Initialize the board. */ init_brown(); /* Process GTP commands. */ gtp_main_loop(commands, stdin, NULL); return 0; }