/* Common code for fixed_handicap and place_free_handicap. */ static int place_handicap(char *s, int fixed) { int handicap; int m, n; int first_stone = 1; if (!board_empty()) return gtp_failure("board not empty"); if (sscanf(s, "%d", &handicap) < 1) return gtp_failure("handicap not an integer"); if (handicap < 2) return gtp_failure("invalid handicap"); if (fixed && !valid_fixed_handicap(handicap)) return gtp_failure("invalid handicap"); if (fixed) place_fixed_handicap(handicap); else place_free_handicap(handicap); gtp_start_response(GTP_SUCCESS); for (m = 0; m < board_size; m++) for (n = 0; n < board_size; n++) if (get_board(m, n) != EMPTY) { if (first_stone) first_stone = 0; else gtp_printf(" "); gtp_mprintf("%m", m, n); } return gtp_finish_response(); }
static void ascii_free_handicap(Gameinfo *gameinfo, char *handicap_string) { int handi; int i; char line[80]; int stones[MAX_BOARD*MAX_BOARD]; if (sscanf(handicap_string, "%d", &handi) == 1) { /* GNU Go is to place handicap */ if (handi < 0 || handi == 1) { printf("\nInvalid command syntax!\n"); return; } clear_board(); handi = place_free_handicap(handi); printf("\nPlaced %d stones of free handicap.\n", handi); } else { /* User is to place handicap */ clear_board(); handi = 0; while (1) { ascii_showboard(); printf("\nType in coordinates of next handicap stone, or one of the following commands:\n"); printf(" undo take back the last stone placed\n"); printf(" clear remove all the stones placed so far\n"); printf(" done finish placing handicap\n\n"); printf("You have placed %d handicap stone(s) so far.\n\n", handi); if (!fgets(line, 80, stdin)) return; /* EOF or some error */ for (i = 0; i < 80; i++) line[i] = tolower((int) line[i]); if (!strncmp(line, "undo", 4)) { if (!handi) printf("\nNothing to undo.\n"); else { remove_stone(stones[--handi]); gprintf("\nRemoved the stone at %m.\n", I(stones[handi]), J(stones[handi])); } } else if (!strncmp(line, "clear", 5)) { clear_board(); handi = 0; } else if (!strncmp(line, "done", 4)) { if (handi == 1) /* Don't bother with checks later */ printf("\nHandicap cannot be one stone. Either add " "some more, or delete the only stone.\n"); else break; } else { int pos = string_to_location(board_size, line); if (pos != NO_MOVE) { if (board[pos] != EMPTY) printf("\nThere's already a stone there.\n"); else { add_stone(pos, BLACK); stones[handi++] = pos; } } else printf("\nInvalid command: %s", line); } } } gameinfo->handicap = handi; gameinfo->to_move = (handi ? WHITE : BLACK); }