Ejemplo n.º 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");
}
Ejemplo n.º 2
0
static float
compute_score()
{
  int i, j;
  float score = komi;

  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++;
      }
    }
  }

  return score;
}
Ejemplo n.º 3
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();
}