Example #1
0
void AgentMCTS::load_sgf(SGFParser<Move> & sgf, const Board & board, Node & node) {
	assert(sgf.has_children());
	create_children_simple(board, & node);

	while(sgf.next_child()){
		Move m = sgf.move();
		Node & child = *find_child(&node, m);
		child.from_s(sgf.comment());
		if(sgf.done_child()){
			continue;
		}else{
			// has children!
			Board b = board;
			b.move(m);
			load_sgf(sgf, b, child);
			assert(sgf.done_child());
		}
	}
}
Example #2
0
int
main (int argc, char **argv)
{
  char *infilename = NULL;
  char *outfilename = NULL;
  char *untilstring = NULL;
  char *fromstring = NULL;
  char *labelstring = NULL;
  int c, index;
  int i, j;
  FILE *sgffile, *mpfile;

  memset(p, 0, sizeof(p));
  memset(label, 0, sizeof(label));
  memset(board_image, 0, sizeof(board_image));
  opterr = 0;
  strcpy(fontstring, DEFAULT_FONT);
  strcpy(italfontstring, ITALIC_FONT);
  strcpy(bignumberstring, BIGNUMBER_FONT);
  
  while ((c = getopt (argc, argv, "b:B:de:F:hi:I:l:L:n:o:r:s:S:t:T:v")) != -1)
    switch (c) {

    case 'i':
      infilename = optarg;
      break;

    case 'o':
      outfilename = optarg;
      break;

    case 's':
      fromstring = optarg;
      break;

    case 'e':
      untilstring = optarg;
      break;

    case 'F':
      strcpy(fontstring, optarg);
      break;

    case 'I':
      strcpy(italfontstring, optarg);
      break;

    case 'B':
      strcpy(bignumberstring, optarg);
      break;

    case 'n': 
      new_number = atoi(optarg);
      break;

    case 'l':
      left_column = atoi(optarg);
      break;

    case 'r':
      right_column = atoi(optarg);
      break;

    case 'b':
      bottom_row = atoi(optarg);
      break;

    case 't':
      top_row = atoi(optarg);
      break;

    case 'd':
      debug = 1;
      break;

    case 'h':
      fprintf(stderr, HELP);
      return 0;

    case 'L':
      {
	char this_label;
	int li, lj;

	labelstring = optarg;      
	this_label = *labelstring;
	labelstring++;
	labelstring++;
	lj = *labelstring - 'A';
	if (*labelstring >= 'I')
	  --lj;
	li = board_size - atoi(labelstring+1);
	label[li][lj] = this_label;
      }
      break;

    case 'T':
      {
	int li, lj;

	labelstring = optarg;
	lj = *labelstring - 'A';
	if (*labelstring >= 'I')
	  --lj;
	li = board_size - atoi(labelstring+1);

	label[li][lj] = -TRIANGLE;
      }
      break;

    case 'S':
      scale = atof(optarg);
      break;

    case 'v':
      fprintf(stderr, "Version %s\n", VERSION);
      return 0;

    case '?':
      if (isprint (optopt))
	fprintf (stderr, "Unknown option `-%c'.\n", optopt);
      else
          fprintf (stderr,
                   "Unknown option character `\\x%x'.\n",
                   optopt);
      fprintf(stderr, HELP);
      return 1;
    default:
      abort ();
    }
  if (!infilename) {
    fprintf(stderr, "sgf2mpost: no input filename given\n");
    fprintf(stderr, HELP);
    return;
  }
  
  if (strcmp(outfilename, "-") == 0) 
    mpfile = stdout;
  else
    mpfile = fopen(outfilename, "w");
  if (!mpfile) {
    fprintf(stderr, "Can not open %s\n", outfilename);
    return;
  }

  sgffile = fopen(infilename, "r");

  load_sgf(sgffile, mpfile, fromstring, untilstring);
  if (!sgffile || fclose(sgffile))
    fprintf(stderr, "unable to close sgf file\n");
  if (!mpfile || fclose(mpfile))
    fprintf(stderr, "unable to close mp file\n");

  return 0;
}