/* Preliminary function for playing through the aftermath. */ static void do_play_aftermath(int color, struct aftermath_data *a) { int move; int pass = 0; int moves = 0; int color_to_play = color; DEBUG(DEBUG_AFTERMATH, "The aftermath starts.\n"); /* Disable computing worm and owl threats. */ disable_threat_computation = 1; /* Disable matching of endgame patterns. */ disable_endgame_patterns = 1; while (pass < 2 && moves < board_size * board_size) { int reading_nodes = get_reading_node_counter(); int owl_nodes = get_owl_node_counter(); int move_val = reduced_genmove(&move, color_to_play); if (move_val < 0) { int save_verbose = verbose; if (verbose > 0) verbose--; move_val = aftermath_genmove(&move, color_to_play, (color_to_play == WHITE ? a->white_control : a->black_control), 0); verbose = save_verbose; } play_move(move, color_to_play); if (aftermath_sgftree) sgftreeAddPlay(aftermath_sgftree, color_to_play, I(move), J(move)); moves++; DEBUG(DEBUG_AFTERMATH, "%d %C move %1m (nodes %d, %d total %d, %d)\n", movenum, color_to_play, move, get_owl_node_counter() - owl_nodes, get_reading_node_counter() - reading_nodes, get_owl_node_counter(), get_reading_node_counter()); if (move != PASS_MOVE) pass = 0; else pass++; color_to_play = OTHER_COLOR(color_to_play); } /* Reenable worm and dragon threats and endgame patterns. */ disable_threat_computation = 0; disable_endgame_patterns = 0; }
void play_solo(Gameinfo *gameinfo, int moves) { SGFTree sgftree; int passes = 0; /* num. consecutive passes */ int move_val; double t1, t2; int save_moves = moves; int boardsize = gnugo_get_boardsize(); struct stats_data totalstats; int total_owl_count = 0; /* It tends not to be very imaginative in the opening, * so we scatter a few stones randomly to start with. * We add two random numbers to reduce the probability * of playing stones near the edge. */ int n = 6 + 2*gg_rand()%5; int i, j; gnugo_set_komi(5.5); sgftree_clear(&sgftree); 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) { do { do { 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)); gnugo_play_move(i, j, gameinfo->to_move); sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j); sgftreeAddComment(&sgftree, "random move"); gameinfo->to_move = OTHER_COLOR(gameinfo->to_move); } while (--n > 0); } t1 = gg_cputime(); memset(&totalstats, '\0', sizeof(totalstats)); while (passes < 2 && --moves >= 0) { reset_owl_node_counter(); move_val = gnugo_genmove(&i, &j, gameinfo->to_move); gnugo_play_move(i, j, gameinfo->to_move); sgffile_add_debuginfo(sgftree.lastnode, move_val); sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j); sgffile_output(&sgftree); gameinfo->to_move = OTHER_COLOR(gameinfo->to_move); if (move_val < 0) { ++passes; printf("%s(%d): Pass\n", gameinfo->to_move == BLACK ? "Black" : "White", movenum); } else { passes = 0; gprintf("%s(%d): %m\n", gameinfo->to_move == BLACK ? "Black" : "White", movenum, i, j); } totalstats.nodes += stats.nodes; totalstats.position_entered += stats.position_entered; totalstats.position_hits += stats.position_hits; totalstats.read_result_entered += stats.read_result_entered; totalstats.hash_collisions += stats.hash_collisions; total_owl_count += get_owl_node_counter(); } t2 = gg_cputime(); /* 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); #if 0 if (t2 == t1) printf("%.3f moves played\n", (double) (save_moves-moves)); else printf("%.3f moves/sec\n", (save_moves-moves)/(t2-t1)); #else printf("%10d moves played in %0.3f seconds\n", save_moves-moves, t2-t1); if (save_moves != moves) printf("%10.3f seconds/move\n", (t2-t1)/(save_moves-moves)); printf("%10d nodes\n", totalstats.nodes); printf("%10d positions entered\n", totalstats.position_entered); printf("%10d position hits\n", totalstats.position_hits); printf("%10d read results entered\n", totalstats.read_result_entered); printf("%10d hash collisions\n", totalstats.hash_collisions); printf("%10d owl nodes\n", total_owl_count); #endif }
void play_solo(Gameinfo *gameinfo, int moves) { SGFTree sgftree; int passes = 0; /* num. consecutive passes */ float move_value; double t1, t2; int save_moves = moves; struct stats_data totalstats; int total_owl_count = 0; /* It tends not to be very imaginative in the opening, * so we scatter a few stones randomly to start with. * We add two random numbers to reduce the probability * of playing stones near the edge. */ int n = 6 + 2*gg_rand()%5; int i, j; komi = 5.5; sgftree_clear(&sgftree); sgftreeCreateHeaderNode(&sgftree, board_size, komi, handicap); sgf_write_header(sgftree.root, 1, get_random_seed(), 5.5, handicap, get_level(), chinese_rules); /* Generate some random moves. */ if (board_size > 6) { do { do { i = (gg_rand() % 4) + (gg_rand() % (board_size - 4)); j = (gg_rand() % 4) + (gg_rand() % (board_size - 4)); } while (!is_allowed_move(POS(i, j), gameinfo->to_move)); gnugo_play_move(POS(i, j), gameinfo->to_move); sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j); sgftreeAddComment(&sgftree, "random move"); gameinfo->to_move = OTHER_COLOR(gameinfo->to_move); } while (--n > 0); } t1 = gg_cputime(); memset(&totalstats, '\0', sizeof(totalstats)); while (passes < 2 && --moves >= 0) { int move; reset_owl_node_counter(); move = genmove(gameinfo->to_move, &move_value, NULL); gnugo_play_move(move, gameinfo->to_move); sgffile_add_debuginfo(sgftree.lastnode, move_value); sgftreeAddPlay(&sgftree, gameinfo->to_move, I(move), J(move)); sgffile_output(&sgftree); gameinfo->to_move = OTHER_COLOR(gameinfo->to_move); if (move == PASS_MOVE) { passes++; printf("%s(%d): Pass\n", gameinfo->to_move == BLACK ? "Black" : "White", movenum); } else { passes = 0; gprintf("%s(%d): %1m\n", gameinfo->to_move == BLACK ? "Black" : "White", movenum, move); } totalstats.nodes += stats.nodes; totalstats.read_result_entered += stats.read_result_entered; totalstats.read_result_hits += stats.read_result_hits; totalstats.trusted_read_result_hits += stats.trusted_read_result_hits; total_owl_count += get_owl_node_counter(); } t2 = gg_cputime(); /* Two passes and it's over. (EMPTY == BOTH) */ who_wins(EMPTY, stdout); { float score = gnugo_estimate_score(NULL, NULL); sgfWriteResult(sgftree.root, score, 1); } sgffile_output(&sgftree); printf("%10d moves played in %0.3f seconds\n", save_moves-moves, t2-t1); if (save_moves != moves) printf("%10.3f seconds/move\n", (t2-t1)/(save_moves-moves)); printf("%10d nodes\n", totalstats.nodes); printf("%10d read results entered\n", totalstats.read_result_entered); printf("%10d read result hits\n", totalstats.read_result_hits); printf("%10d trusted read result hits\n", totalstats.trusted_read_result_hits); printf("%10d owl nodes\n", total_owl_count); }