- gameinfo->handicap = place_fixed_handicap(num);
- printf("\nSet handicap to %d\n", gameinfo->handicap);
- gameinfo->to_move = (gameinfo->handicap ? WHITE : BLACK);
- break;
-
- case FREEHANDICAP:
- if (sgf_initialized) {
- printf("Handicap cannot be changed after game is started!\n");
- break;
- }
- while (*command && *command != ' ')
- command++;
- ascii_free_handicap(gameinfo, command);
- break;
-
- case SETKOMI:
- if (sgf_initialized) {
- printf("Komi cannot be modified after game record is started!\n");
- break;
- }
- command += 5;
- if (sscanf(command, "%f", &fnum) != 1) {
- printf("\nInvalid command syntax!\n");
- break;
- }
- komi = fnum;
- printf("\nSet Komi to %.1f\n", komi);
- break;
-
- case SETDEPTH:
- command += 6;
- if (sscanf(command, "%d", &num) != 1) {
- printf("\nInvalid command syntax!\n");
- break;
- }
- mandated_depth = num;
- printf("\nSet depth to %d\n", mandated_depth);
- break;
-
- case SETLEVEL:
- command += 6;
- if (sscanf(command, "%d", &num) != 1) {
- printf("\nInvalid command syntax!\n");
- break;
- }
- set_level(num);
- printf("\nSet level to %d\n", num);
- break;
-
- case DISPLAY:
- if (!opt_showboard)
- ascii_showboard();
- break;
-
- case FORCE:
- command += 6; /* skip the force part... */
- switch (get_command(command)) {
- case MOVE:
- state = do_move(gameinfo, command, &passes, 1);
- break;
- case PASS:
- state = do_pass(gameinfo, &passes, 1);
- break;
- default:
- printf("Illegal forced move: %s %d\n", command,
- get_command(command));
- break;
- }
- break;
-
- case MOVE:
- state = do_move(gameinfo, command, &passes, 0);
- break;
-
- case PASS:
- state = do_pass(gameinfo, &passes, 0);
- break;
-
- case PLAY:
- command += 5;
- if (sscanf(command, "%d", &num) != 1) {
- printf("\nInvalid command syntax!\n");
- break;
- }
- if (num >= 0)
- for (m = 0; m < num; m++) {
- gameinfo->computer_player
- = OTHER_COLOR(gameinfo->computer_player);
- state = computer_move(gameinfo, &passes);
- if (state)
- break;
- if (passes >= 2)
- break;
- }
- else {
- printf("\nInvalid number of moves specified: %d\n", num);
- break;
- }
- break;
-
- case PLAYBLACK:
- if (gameinfo->computer_player == WHITE)
- gameinfo->computer_player = BLACK;
- if (gameinfo->computer_player == gameinfo->to_move)
- state = computer_move(gameinfo, &passes);
- break;
-
- case PLAYWHITE:
- if (gameinfo->computer_player == BLACK)
- gameinfo->computer_player = WHITE;
- if (gameinfo->computer_player == gameinfo->to_move)
- state = computer_move(gameinfo, &passes);
- break;
-
- case SWITCH:
- gameinfo->computer_player = OTHER_COLOR(gameinfo->computer_player);
- state = computer_move(gameinfo, &passes);
- break;
-
- case UNDO:
- case CMD_BACK:
- if (undo_move(1)) {
- sgftreeAddComment(&sgftree, "undone");
- sgftreeBack(&sgftree);
- gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
- }
- else
- printf("\nCan't undo.\n");
- break;
-
- case CMD_FORWARD:
- if (sgftreeForward(&sgftree))
- gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode,
- gameinfo->to_move);
- else
- printf("\nEnd of game tree.\n");
- break;
-
- case CMD_LAST:
- while (sgftreeForward(&sgftree))
- gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode,
- gameinfo->to_move);
- break;
-
- case COMMENT:
- printf("\nEnter comment. Press ENTER when ready.\n");
- fgets(line, 80, stdin);
- sgftreeAddComment(&sgftree, line);
- break;
-
- case SCORE:
- showscore = !showscore;
- if (!showscore)
- current_score_estimate = NO_SCORE;
- break;
-
- case CMD_DEAD:
- silent_examine_position(FULL_EXAMINE_DRAGONS);
- showdead = !showdead;
- break;
-
- case CMD_CAPTURE:
- strtok(command, " ");
- showcapture(strtok(NULL, " "));
- break;
-
- case CMD_DEFEND:
- strtok(command, " ");
- showdefense(strtok(NULL, " "));
- break;
-
- case CMD_SHOWMOYO:
- tmp = printmoyo;
- printmoyo = PRINTMOYO_MOYO;
- silent_examine_position(EXAMINE_DRAGONS);
- printmoyo = tmp;
- break;
-
- case CMD_SHOWTERRI:
- tmp = printmoyo;
- printmoyo = PRINTMOYO_TERRITORY;
- silent_examine_position(EXAMINE_DRAGONS);
- printmoyo = tmp;
- break;
-
- case CMD_SHOWAREA:
- tmp = printmoyo;
- printmoyo = PRINTMOYO_AREA;
- silent_examine_position(EXAMINE_DRAGONS);
- printmoyo = tmp;
- break;
-
- case CMD_SHOWDRAGONS:
- silent_examine_position(EXAMINE_DRAGONS);
- showboard(1);
- break;
-
- case CMD_GOTO:
- strtok(command, " ");
- ascii_goto(gameinfo, strtok(NULL, " "));
- break;
-
- case CMD_SAVE:
- strtok(command, " ");
- tmpstring = strtok(NULL, " ");
- if (tmpstring) {
- /* discard newline */
- tmpstring[strlen(tmpstring) - 1] = 0;
- /* make sure we are saving proper handicap */
- init_sgf(gameinfo);
- writesgf(sgftree.root, tmpstring);
- printf("You may resume the game");
- printf(" with -l %s --mode ascii\n", tmpstring);
- printf("or load %s\n", tmpstring);
- }
- else
- printf("Please specify filename\n");
- break;
-
- case CMD_LOAD:
- strtok(command, " ");
- tmpstring = strtok(NULL, " ");
- if (tmpstring) {
- /* discard newline */
- tmpstring[strlen(tmpstring) - 1] = 0;
- if (!sgftree_readfile(&sgftree, tmpstring)) {
- fprintf(stderr, "Cannot open or parse '%s'\n", tmpstring);
- break;
- }
- /* to avoid changing handicap etc. */
- if (gameinfo_play_sgftree(gameinfo, &sgftree, NULL) == EMPTY)
- fprintf(stderr, "Cannot load '%s'\n", tmpstring);
- else {
- sgf_initialized = 1;
- sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap);
- }
- }
- else
- printf("Please specify a filename\n");
- break;
-
- case CMD_LISTDRAGONS:
- silent_examine_position(EXAMINE_DRAGONS);
- show_dragons();
- break;
-
- default:
- printf("\nInvalid command: %s", command);
- break;
- }
-
- if (passes >= 2)
- state = ascii_endgame(gameinfo, 0);
- }
+ gameinfo->handicap = place_fixed_handicap(num);
+ printf("\nSet handicap to %d\n", gameinfo->handicap);
+ gameinfo->to_move = (gameinfo->handicap ? WHITE : BLACK);
+ break;
+
+ case FREEHANDICAP:
+ if (sgf_initialized) {
+ printf("Handicap cannot be changed after game is started!\n");
+ break;
+ }
+ while (*command && *command != ' ')
+ command++;
+ ascii_free_handicap(gameinfo, command);
+ break;
+
+ case SETKOMI:
+ if (sgf_initialized) {
+ printf("Komi cannot be modified after game record is started!\n");
+ break;
+ }
+ command += 5;
+ if (sscanf(command, "%f", &fnum) != 1) {
+ printf("\nInvalid command syntax!\n");
+ break;
+ }
+ komi = fnum;
+ printf("\nSet Komi to %.1f\n", komi);
+ break;
+
+ case SETDEPTH:
+ command += 6;
+ if (sscanf(command, "%d", &num) != 1) {
+ printf("\nInvalid command syntax!\n");
+ break;
+ }
+ mandated_depth = num;
+ printf("\nSet depth to %d\n", mandated_depth);
+ break;
+
+ case SETLEVEL:
+ command += 6;
+ if (sscanf(command, "%d", &num) != 1) {
+ printf("\nInvalid command syntax!\n");
+ break;
+ }
+ set_level(num);
+ printf("\nSet level to %d\n", num);
+ break;
+
+ case DISPLAY:
+ if (!opt_showboard)
+ ascii_showboard();
+ break;
+
+ case FORCE:
+ command += 6; /* skip the force part... */
+ switch (get_command(command)) {
+ case MOVE:
+ state = do_move(gameinfo, command, &passes, 1);
+ break;
+ case PASS:
+ state = do_pass(gameinfo, &passes, 1);
+ break;
+ default:
+ printf("Illegal forced move: %s %d\n", command,
+ get_command(command));
+ break;
+ }
+ break;
+
+ case MOVE:
+ state = do_move(gameinfo, command, &passes, 0);
+ break;
+
+ case PASS:
+ state = do_pass(gameinfo, &passes, 0);
+ break;
+
+ case PLAY:
+ command += 5;
+ if (sscanf(command, "%d", &num) != 1) {
+ printf("\nInvalid command syntax!\n");
+ break;
+ }
+ if (num >= 0)
+ for (m = 0; m < num; m++) {
+ gameinfo->computer_player
+ = OTHER_COLOR(gameinfo->computer_player);
+ state = computer_move(gameinfo, &passes);
+ if (state)
+ break;
+ if (passes >= 2)
+ break;
+ }
+ else {
+ printf("\nInvalid number of moves specified: %d\n", num);
+ break;
+ }
+ break;
+
+ case PLAYBLACK:
+ if (gameinfo->computer_player == WHITE)
+ gameinfo->computer_player = BLACK;
+ if (gameinfo->computer_player == gameinfo->to_move)
+ state = computer_move(gameinfo, &passes);
+ break;
+
+ case PLAYWHITE:
+ if (gameinfo->computer_player == BLACK)
+ gameinfo->computer_player = WHITE;
+ if (gameinfo->computer_player == gameinfo->to_move)
+ state = computer_move(gameinfo, &passes);
+ break;
+
+ case SWITCH:
+ gameinfo->computer_player = OTHER_COLOR(gameinfo->computer_player);
+ state = computer_move(gameinfo, &passes);
+ break;
+
+ case UNDO:
+ case CMD_BACK:
+ if (undo_move(1)) {
+ sgftreeAddComment(&sgftree, "undone");
+ sgftreeBack(&sgftree);
+ gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
+ } else
+ printf("\nCan't undo.\n");
+ break;
+
+ case CMD_FORWARD:
+ if (sgftreeForward(&sgftree))
+ gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode,
+ gameinfo->to_move);
+ else
+ printf("\nEnd of game tree.\n");
+ break;
+
+ case CMD_LAST:
+ while (sgftreeForward(&sgftree))
+ gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode,
+ gameinfo->to_move);
+ break;
+
+ case COMMENT:
+ printf("\nEnter comment. Press ENTER when ready.\n");
+ fgets(line, 80, stdin);
+ sgftreeAddComment(&sgftree, line);
+ break;
+
+ case SCORE:
+ showscore = !showscore;
+ if (!showscore)
+ current_score_estimate = NO_SCORE;
+ break;
+
+ case CMD_DEAD:
+ silent_examine_position(FULL_EXAMINE_DRAGONS);
+ showdead = !showdead;
+ break;
+
+ case CMD_CAPTURE:
+ strtok(command, " ");
+ showcapture(strtok(NULL, " "));
+ break;
+
+ case CMD_DEFEND:
+ strtok(command, " ");
+ showdefense(strtok(NULL, " "));
+ break;
+
+ case CMD_SHOWMOYO:
+ tmp = printmoyo;
+ printmoyo = PRINTMOYO_MOYO;
+ silent_examine_position(EXAMINE_DRAGONS);
+ printmoyo = tmp;
+ break;
+
+ case CMD_SHOWTERRI:
+ tmp = printmoyo;
+ printmoyo = PRINTMOYO_TERRITORY;
+ silent_examine_position(EXAMINE_DRAGONS);
+ printmoyo = tmp;
+ break;
+
+ case CMD_SHOWAREA:
+ tmp = printmoyo;
+ printmoyo = PRINTMOYO_AREA;
+ silent_examine_position(EXAMINE_DRAGONS);
+ printmoyo = tmp;
+ break;
+
+ case CMD_SHOWDRAGONS:
+ silent_examine_position(EXAMINE_DRAGONS);
+ showboard(1);
+ break;
+
+ case CMD_GOTO:
+ strtok(command, " ");
+ ascii_goto(gameinfo, strtok(NULL, " "));
+ break;
+
+ case CMD_SAVE:
+ strtok(command, " ");
+ tmpstring = strtok(NULL, " ");
+ if (tmpstring) {
+ /* discard newline */
+ tmpstring[strlen(tmpstring) - 1] = 0;
+ /* make sure we are saving proper handicap */
+ init_sgf(gameinfo);
+ writesgf(sgftree.root, tmpstring);
+ printf("You may resume the game");
+ printf(" with -l %s --mode ascii\n", tmpstring);
+ printf("or load %s\n", tmpstring);
+ } else
+ printf("Please specify filename\n");
+ break;
+
+ case CMD_LOAD:
+ strtok(command, " ");
+ tmpstring = strtok(NULL, " ");
+ if (tmpstring) {
+ /* discard newline */
+ tmpstring[strlen(tmpstring) - 1] = 0;
+ if (!sgftree_readfile(&sgftree, tmpstring)) {
+ fprintf(stderr, "Cannot open or parse '%s'\n", tmpstring);
+ break;
+ }
+ /* to avoid changing handicap etc. */
+ if (gameinfo_play_sgftree(gameinfo, &sgftree, NULL) == EMPTY)
+ fprintf(stderr, "Cannot load '%s'\n", tmpstring);
+ else {
+ sgf_initialized = 1;
+ sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap);
+ }
+ } else
+ printf("Please specify a filename\n");
+ break;
+
+ case CMD_LISTDRAGONS:
+ silent_examine_position(EXAMINE_DRAGONS);
+ show_dragons();
+ break;
+
+ default:
+ printf("\nInvalid command: %s", command);
+ break;
+ }
+
+ if (passes >= 2)
+ state = ascii_endgame(gameinfo, 0);
+ }