Beispiel #1
0
/* Function:  Show debug info related to patterns to stdout.
 * Arguments: none
 * Fails:     never
 * Returns:   nothing
 *
 */
static int gtp_match_patterns(char *s) {
  UNUSED(s);

  gtp_start_response(GTP_SUCCESS);
  gtp_printf("\n");
  game->match_patterns();
  return gtp_finish_response();
}
Beispiel #2
0
/* Function:  Write the debug info to stdout.
 * Arguments: none
 * Fails:     never
 * Returns:   nothing
 *
 */
static int gtp_debug(char *s) {
  UNUSED(s);

  gtp_start_response(GTP_SUCCESS);
  gtp_printf("\n");
  game->debug();
  return gtp_finish_response();
}
Beispiel #3
0
/* Function:  Write the position to stdout.
 * Arguments: none
 * Fails:     never
 * Returns:   nothing
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_showboard(char *s) {
  UNUSED(s);

  gtp_start_response(GTP_SUCCESS);
  gtp_printf("\n");
  game->show_board(gtp_output_file);
  return gtp_finish_response();
}
Beispiel #4
0
/* Function:  Compute the score of a finished game.
 * Arguments: Optional random seed
 * Fails:     never
 * Returns:   Score in SGF format (RE property).
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_final_score(char *s) {
  float final_score = game->get_final_score();
  gtp_start_response(GTP_SUCCESS);
  if (final_score > 0.0)
    gtp_printf("W+%3.1f", final_score);
  else if (final_score < 0.0)
    gtp_printf("B+%3.1f", -final_score);
  else
    gtp_printf("0");
  return gtp_finish_response();
}
Beispiel #5
0
static int
gtp_genmove(char *s)
{
  int i, j;
  int color = EMPTY;

  if (!gtp_decode_color(s, &color))
    return gtp_failure("invalid color");

  generate_move(&i, &j, color);
  play_move(i, j, color);

  gtp_start_response(GTP_SUCCESS);
  gtp_mprintf("%m", i, j);
  return gtp_finish_response();
}
Beispiel #6
0
static int
gtp_final_status_list(char *s)
{
  int n;
  int i, j;
  int status = UNKNOWN;
  char status_string[GTP_BUFSIZE];
  int first_string;

  if (sscanf(s, "%s %n", status_string, &n) != 1)
    return gtp_failure("missing status");

  if (!strcmp(status_string, "alive"))
    status = ALIVE;
  else if (!strcmp(status_string, "dead"))
    status = DEAD;
  else if (!strcmp(status_string, "seki"))
    status = SEKI;
  else
    return gtp_failure("invalid status");

  compute_final_status();

  gtp_start_response(GTP_SUCCESS);

  first_string = 1;
  for (i = 0; i < board_size; i++)
    for (j = 0; j < board_size; j++)
      if (get_final_status(i, j) == status) {
	int k;
	int stonei[MAX_BOARD * MAX_BOARD];
	int stonej[MAX_BOARD * MAX_BOARD];
	int num_stones = get_string(i, j, stonei, stonej);
	/* Clear the status so we don't find the string again. */
	for (k = 0; k < num_stones; k++)
	  set_final_status(stonei[k], stonej[k], UNKNOWN);
	
	if (first_string)
	  first_string = 0;
	else
	  gtp_printf("\n");
	
	gtp_print_vertices(num_stones, stonei, stonej);
      }

  return gtp_finish_response();
}
Beispiel #7
0
/* Function:  Generate and play the supposedly best move for either color.
 * Arguments: color to move
 * Fails:     invalid color
 * Returns:   a move coordinate or "PASS" (or "resign" if resignation_allowed)
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_genmove(char *s) {
  DataGo move;
  Player color;

  if (!gtp_decode_color(s, &color))
    return gtp_failure("invalid color");

  move = game->gen_move(color);

  if (IS_RESIGN(move))
    return gtp_success("resign");

  assert(game->play_move(move));
  gtp_start_response(GTP_SUCCESS);
  if (IS_PASS(move))
    gtp_print_vertex(-1, -1);
  else
    gtp_print_vertex(move.i, move.j);
  return gtp_finish_response();
}
Beispiel #8
0
static int
gtp_showboard(char *s)
{
  int i, j;
  int symbols[3] = {'.', 'O', 'X'};
  
  gtp_start_response(GTP_SUCCESS);
  gtp_printf("\n");

  letters();
  
  for (i = 0; i < board_size; i++) {
    printf("\n%2d", board_size - i);
    
    for (j = 0; j < board_size; j++)
      printf(" %c", symbols[get_board(i, j)]);

    printf(" %d", board_size - i);
  }
  
  printf("\n");
  letters();
  return gtp_finish_response();
}
Beispiel #9
0
/* 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();
}