[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnugo-devel] sgf output in play_solo.c
From: |
Paul Pogonyshev |
Subject: |
[gnugo-devel] sgf output in play_solo.c |
Date: |
Fri, 6 Sep 2002 00:24:57 +0300 |
changes:
- play_solo.c now outputs sgf files using trees
- play_ascii.c writes game result to sgf files
- main.c should now output "You must use -l infile with ... mode"
- changed help messages a bit (main.c)
current issues:
- trees in load and analyze, ascii and possibly some other modes
doesn't work well with -L option. however, previous approach
didn't work well either. fixing it can involve some deeper changes
in sgf handling. i think migration to trees should be finished
before dealing with this problem.
Index: interface/play_solo.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_solo.c,v
retrieving revision 1.15
diff -u -r1.15 play_solo.c
--- interface/play_solo.c 4 Sep 2002 07:23:46 -0000 1.15
+++ interface/play_solo.c 5 Sep 2002 21:14:23 -0000
@@ -34,6 +34,8 @@
#include "random.h"
#include "gg_utils.h"
+SGFTree sgftree;
+SGFNode *curnode;
void
play_solo(Gameinfo *gameinfo, int moves)
@@ -56,7 +58,11 @@
int n = 6 + 2*gg_rand()%5;
int i, j;
- sgffile_write_gameinfo(gameinfo, "solo");
+ gnugo_set_komi(5.5);
+
+ sgftree_clear(&sgftree);
+ curnode = sgftreeCreateHeaderNode(&sgftree, gnugo_get_boardsize(),
gnugo_get_komi());
+ sgf_write_header(sgftree.root, 1, random_seed, 5.5, level, chinese_rules);
/* Generate some random moves. */
if (boardsize > 6) {
@@ -65,8 +71,11 @@
i = (gg_rand() % 4) + (gg_rand() % (boardsize - 4));
j = (gg_rand() % 4) + (gg_rand() % (boardsize - 4));
} while (!gnugo_is_legal(i, j, gameinfo->to_move));
-
- gameinfo_play_move(gameinfo, i, j, gameinfo->to_move);
+
+ gnugo_play_move(i, j, gameinfo->to_move);
+ curnode = sgfAddPlay(curnode, gameinfo->to_move, i, j);
+ sgfAddComment(curnode, "random move");
+ gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
} while (--n > 0);
}
@@ -75,7 +84,12 @@
while (passes < 2 && --moves >= 0 && !time_to_die) {
reset_owl_node_counter();
move_val = gnugo_genmove(&i, &j, gameinfo->to_move);
- gameinfo_play_move(gameinfo, i, j, gameinfo->to_move);
+
+ gnugo_play_move(i, j, gameinfo->to_move);
+ sgffile_debuginfo(curnode, move_val);
+ curnode = sgfAddPlay(curnode, gameinfo->to_move, i, j);
+ sgffile_output(sgftree.root);
+ gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
if (move_val < 0) {
++passes;
@@ -100,6 +114,10 @@
/* Two passes and it's over. (EMPTY == BOTH) */
gnugo_who_wins(EMPTY, stdout);
+ score = gnugo_estimate_score(&lower_bound, &upper_bound);
+ sgfWriteResult(sgftree.root, score, 1);
+ sgffile_output(sgftree.root);
+
#if 0
if (t2 == t1)
printf("%.3f moves played\n", (double) (save_moves-moves));
@@ -136,31 +154,23 @@
int i, j;
int next;
int r;
+ int move_val;
next = gameinfo->to_move;
- gameinfo->computer_player = next;
- sgffile_write_gameinfo(gameinfo, "load and analyze");
+ sgftree = gameinfo->game_record;
- if (benchmark) {
- for (r = 0; r < benchmark; ++r) {
- genmove(&i, &j, next);
- next = OTHER_COLOR(next);
- }
- }
- else {
- genmove(&i, &j, next);
-
- if (is_pass(POS(i, j))) {
- gprintf("%s move: PASS!\n", next == WHITE ? "white (O)" : "black (X)");
- sgffile_move_made(i, j, next, 0);
- }
- else {
- gprintf("%s move %m\n", next == WHITE ? "white (O)" : "black (X)",
- i, j);
- gnugo_play_move(i, j, next);
- sgffile_move_made(i, j, next, 0);
- }
- }
+ move_val = gnugo_genmove(&i, &j, next);
+
+ if (is_pass(POS(i, j)))
+ gprintf("%s move: PASS!\n", next == WHITE ? "white (O)" : "black (X)");
+ else
+ gprintf("%s move %m\n", next == WHITE ? "white (O)" : "black (X)",
+ i, j);
+ curnode = sgftreeNodeCheck(&sgftree, 0);
+ curnode = sgfAddPlay(curnode, next, i, j);
+ sgfAddComment(curnode, "load and analyze mode");
+ sgffile_debuginfo(curnode, move_val);
+ sgffile_output(sgftree.root);
}
@@ -194,9 +204,9 @@
sgftreeSetLastNode(&score_tree, node);
sgftree_printboard(&score_tree);
- sgffile_write_gameinfo(gameinfo, "load and score");
next = gameinfo->to_move;
sgffile_printboard(next);
+ node = node->child;
doing_scoring = 1;
reset_engine();
@@ -215,13 +225,13 @@
next == WHITE ? "white (O)" : "black (X)");
}
play_move(POS(i, j), next);
- sgffile_move_made(i, j, next, move_val);
- sgftreeAddPlay(&score_tree, NULL, next, i, j);
+ sgffile_debuginfo(node, move_val);
+ node = sgfAddPlay(node, next, i, j);
+ sgffile_output(score_tree.root);
next = OTHER_COLOR(next);
} while (movenum <= until && pass < 2);
if (pass >= 2) {
- node = score_tree.lastnode;
/* Calculate the score */
if (!strcmp(scoringmode, "aftermath"))
score = aftermath_compute_score(next, komi, &score_tree);
@@ -265,26 +275,23 @@
}
}
sgfWriteResult(score_tree.root, score, 1);
+ sgffile_output(score_tree.root);
}
}
doing_scoring = 0;
- if (!strcmp(scoringmode, "aftermath")) {
- if (gameinfo->outfilename)
- writesgf(score_tree.root, gameinfo->outfilename);
- return;
+ if (strcmp(scoringmode, "aftermath")) {
+ /* Before we call estimate_score() we must make sure that the dragon
+ * status is computed. Therefore the call to examine_position().
+ */
+ examine_position(next, EXAMINE_ALL);
+ score = estimate_score(NULL, NULL);
+
+ fprintf(stdout, "\n%s seems to win by %1.1f points\n",
+ score < 0 ? "B" : "W",
+ score < 0 ? -score : score);
}
-
- /* Before we call estimate_score() we must make sure that the dragon
- * status is computed. Therefore the call to examine_position().
- */
- examine_position(next, EXAMINE_ALL);
- score = estimate_score(NULL, NULL);
-
- fprintf(stdout, "\n%s seems to win by %1.1f points\n",
- score < 0 ? "B" : "W",
- score < 0 ? -score : score);
}
Index: interface/play_ascii.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_ascii.c,v
retrieving revision 1.23
diff -u -r1.23 play_ascii.c
--- interface/play_ascii.c 3 Sep 2002 00:28:12 -0000 1.23
+++ interface/play_ascii.c 5 Sep 2002 21:14:25 -0000
@@ -617,6 +617,7 @@
sgftreeWriteResult(&sgftree,
gameinfo->to_move == WHITE ? -1000.0 : 1000.0,
1);
+ sgffile_output(sgftree.root);
case END:
case EXIT:
case QUIT:
@@ -940,7 +941,7 @@
if (tmpstring) {
/* discard newline */
tmpstring[strlen(tmpstring)-1] = 0;
- init_sgf(gameinfo,sgftree.root);
+ init_sgf(gameinfo,sgftree.root);
writesgf(sgftree.root, tmpstring);
}
else
@@ -963,6 +964,8 @@
state = 0;
}
}
+ sgftreeWriteResult(&sgftree, estimate_score(NULL, NULL), 1);
+ sgffile_output(sgftree.root);
passes = 0;
showdead = 0;
/* Play a different game next time. */
Index: interface/main.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/main.c,v
retrieving revision 1.45
diff -u -r1.45 main.c
--- interface/main.c 3 Sep 2002 00:28:12 -0000 1.45
+++ interface/main.c 5 Sep 2002 21:14:28 -0000
@@ -881,9 +881,8 @@
gameinfo_play_sgftree_rot(&gameinfo, sgftree.root,
untilstring, orientation);
}
-
+ else
/* Initialize and empty sgf tree if there was no infile. */
- if (!sgftree.root)
sgftreeCreateHeaderNode(&sgftree, board_size, komi);
/* Set the game_record to be identical to the loaded one or the
@@ -917,10 +916,10 @@
&& playmode != MODE_DECIDE_TACTICAL_SEMEAI
&& playmode != MODE_DECIDE_EYE
&& playmode != MODE_DECIDE_COMBINATION)
- if (!sgffile_open_file(outfile)) {
+ /*if (!sgffile_open_file(outfile)) {
fprintf(stderr, "Error: could not open '%s'\n", gg_optarg);
exit(EXIT_FAILURE);
- }
+ }*/;
}
switch (playmode) {
@@ -933,7 +932,7 @@
break;
case MODE_REPLAY:
- if (!sgftree.root) {
+ if (!infilename) {
fprintf(stderr, "You must use -l infile with replay mode.\n");
exit(EXIT_FAILURE);
}
@@ -944,7 +943,7 @@
if (mandated_color != EMPTY)
gameinfo.to_move = mandated_color;
- if (!sgftree.root) {
+ if (!infilename) {
fprintf(stderr, "You must use -l infile with load and analyze mode.\n");
exit(EXIT_FAILURE);
}
@@ -952,7 +951,7 @@
break;
case MODE_LOAD_AND_SCORE:
- if (!sgftree.root) {
+ if (!infilename) {
fprintf(stderr, "gnugo: --score must be used with -l\n");
exit(EXIT_FAILURE);
}
@@ -960,7 +959,7 @@
break;
case MODE_LOAD_AND_PRINT:
- if (!sgftree.root) {
+ if (!infilename) {
fprintf(stderr, "gnugo: --printsgf must be used with -l\n");
exit(EXIT_FAILURE);
}
@@ -1299,7 +1298,7 @@
--score estimate estimate score at loaded position\n\
--score finish generate moves to finish game, then score\n\
--score aftermath generate moves to finish, use best algorithm\n\
- --score aftermath --capture-all-dead --chinese rules Tromp-Taylor score\n\
+ --score aftermath --capture-all-dead --chinese-rules Tromp-Taylor score\n\
\n\
Cache size (higher=more memory usage, faster unless swapping occurs):\n\
-M, --cache-size <megabytes> RAM cache for hashing (default %4.1f Mb)\n\
@@ -1365,7 +1364,7 @@
-O, --output-flags <flags> optional output (use with -o)\n\
d: mark dead and critical dragons\n\
v: show values of considered moves\n\
- specify either no flags (default), 'd', 'v' or 'dv'\n\
+ specify either 'd', 'v' or 'dv' (nothing by default)\n\
--showtime print timing diagnostic\n\
--replay <color> replay game. Use with -o.\n\
--showscore print estimated score\n\
- [gnugo-devel] sgf output in play_solo.c,
Paul Pogonyshev <=