Exemple #1
0
/* Compute final score. We use area scoring since that is the only
 * option that makes sense for this move generation algorithm.
 */
static int
gtp_final_score(char *s)
{
  float score = komi;
  int i, j;

  compute_final_status();
  for (i = 0; i < board_size; i++)
    for (j = 0; j < board_size; j++) {
      int status = get_final_status(i, j);
      if (status == BLACK_TERRITORY)
	score--;
      else if (status == WHITE_TERRITORY)
	score++;
      else if ((status == ALIVE) ^ (get_board(i, j) == WHITE))
	score--;
      else
	score++;
    }

  if (score > 0.0)
    return gtp_success("W+%3.1f", score);
  if (score < 0.0)
    return gtp_success("B+%3.1f", -score);
  return gtp_success("0");
}
Exemple #2
0
/* Function:  Tell whether a command is known.
 * Arguments: command name
 * Fails:     never
 * Returns:   "true" if command exists, "false" if not
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_known_command(char *s) {
  int k;
  char command[GTP_BUFSIZE];

  if (sscanf(s, "%s", command) == 1) {
    for (k = 0; commands[k].name != NULL; k++)
      if (strcmp(command, commands[k].name) == 0)
        return gtp_success("true");
  }

  return gtp_success("false");
}
Exemple #3
0
/* Function:  Clear the board.
 * Arguments: none
 * Fails:     never
 * Returns:   nothing
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_clear_board(char *s) {
  UNUSED(s);

  game->clear_board();

  return gtp_success("");
}
Exemple #4
0
static int
gtp_set_free_handicap(char *s)
{
  int i, j;
  int n;
  int handicap = 0;
  
  if (!board_empty())
    return gtp_failure("board not empty");

  while ((n = gtp_decode_coord(s, &i, &j)) > 0) {
    s += n;
    
    if (get_board(i, j) != EMPTY) {
      clear_board();
      return gtp_failure("repeated vertex");
    }

    play_move(i, j, BLACK);
    handicap++;
  }

  if (sscanf(s, "%*s") != EOF) {
      clear_board();
      return gtp_failure("invalid coordinate");
  }

  if (handicap < 2 || handicap >= board_size * board_size) {
      clear_board();
      return gtp_failure("invalid handicap");
  }

  return gtp_success("");
}
Exemple #5
0
static int
gtp_komi(char *s)
{
  if (sscanf(s, "%f", &komi) < 1)
    return gtp_failure("komi not a float");
  
  return gtp_success("");
}
Exemple #6
0
static int
gtp_known_command(char *s)
{
  int i;
  char command_name[GTP_BUFSIZE];

  /* If no command name supplied, return false (this command never
   * fails according to specification).
   */
  if (sscanf(s, "%s", command_name) < 1)
    return gtp_success("false");
  
  for (i = 0; commands[i].name; i++)
    if (!strcmp(command_name, commands[i].name))
      return gtp_success("true");
  
  return gtp_success("false");
}
Exemple #7
0
static int gtp_set_komi(char *s) {
  float komi;
  if (sscanf(s, "%f", &komi) < 1)
    return gtp_failure("komi not a float");

  game->set_komi(komi);

  return gtp_success("");
}
Exemple #8
0
/* Function:  Play a stone of the given color at the given vertex.
 * Arguments: color, vertex
 * Fails:     invalid vertex, illegal move
 * Returns:   nothing
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_play(char *s) {
  DataGo move;

  if (!gtp_decode_move(s, &move))
    return gtp_failure("invalid color or coordinate");

  if (!game->play_move(move))
    return gtp_failure("illegal move");

  return gtp_success("");
}
Exemple #9
0
static int
gtp_play(char *s)
{
  int i, j;
  int color = EMPTY;

  if (!gtp_decode_move(s, &color, &i, &j))
    return gtp_failure("invalid color or coordinate");

  if (!legal_move(i, j, color))
    return gtp_failure("illegal move");

  play_move(i, j, color);
  return gtp_success("");
}
Exemple #10
0
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("");
}
Exemple #11
0
/* 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("");
}
Exemple #12
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();
}
Exemple #13
0
/* Function:  Report the name of the program.
 * Arguments: none
 * Fails:     never
 * Returns:   program name
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_name(char *s) {
  UNUSED(s);
  return gtp_success("Marcos Go");
}
Exemple #14
0
static int
gtp_clear_board(char *s)
{
  clear_board();
  return gtp_success("");
}
Exemple #15
0
static int
gtp_quit(char *s)
{
  gtp_success("");
  return GTP_QUIT;
}
Exemple #16
0
static int
gtp_version(char *s)
{
  return gtp_success(VERSION_STRING);
}
Exemple #17
0
static int
gtp_name(char *s)
{
  return gtp_success("Brown");
}
Exemple #18
0
/* Function:  Report protocol version.
 * Arguments: none
 * Fails:     never
 * Returns:   protocol version number
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_protocol_version(char *s) {
  UNUSED(s);
  return gtp_success("%d", GTP_VERSION);
}
Exemple #19
0
/* Function:  Quit
 * Arguments: none
 * Fails:     never
 * Returns:   nothing
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_quit(char *s) {
  UNUSED(s);
  gtp_success("");
  return GTP_QUIT;
}
Exemple #20
0
/* We are talking version 2 of the protocol. */
static int
gtp_protocol_version(char *s)
{
  return gtp_success("2");
}
Exemple #21
0
/* Function:  Report the version number of the program.
 * Arguments: none
 * Fails:     never
 * Returns:   version number
 *
 * Status:    GTP version 2 standard command.
 */
static int gtp_program_version(char *s) {
  UNUSED(s);
  return gtp_success(VERSION);
}