/* 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; }
/* * Sets up free placement handicap stones, returning the number of * placed handicap stones and also setting the global variable * handicap to the same value. */ int place_free_handicap(int desired_handicap) { gg_assert(desired_handicap == 0 || desired_handicap >= 2); if (desired_handicap == 0) { handicap = 0; return 0; } total_handicap_stones = desired_handicap; remaining_handicap_stones = desired_handicap; /* First place black stones in the four corners to enable the * pattern matching scheme. */ add_stone(POS(0, 0), BLACK); add_stone(POS(0, board_size - 1), BLACK); add_stone(POS(board_size - 1, 0), BLACK); add_stone(POS(board_size - 1, board_size - 1), BLACK); /* Find and place free handicap stones by pattern matching. */ while (remaining_handicap_stones > 0) { if (!find_free_handicap_pattern()) break; } /* Remove the artificial corner stones. */ remove_stone(POS(0, 0)); remove_stone(POS(0, board_size - 1)); remove_stone(POS(board_size - 1, 0)); remove_stone(POS(board_size - 1, board_size - 1)); /* Find and place additional free handicap stones by the aftermath * algorithm. */ while (remaining_handicap_stones > 0) { int move; /* Call genmove_conservative() in order to prepare the engine for * an aftermath_genmove() call. We discard the genmove result. */ genmove_conservative(BLACK, NULL); move = aftermath_genmove(BLACK, 0, NULL); if (move != PASS_MOVE) { add_stone(move, BLACK); remaining_handicap_stones--; } else break; } /* Set handicap to the number of actually placed stones. */ handicap = desired_handicap - remaining_handicap_stones; /* Reset these to invalid values, so that improper use of handicap * helper functions can be detected. */ total_handicap_stones = -1; remaining_handicap_stones = -1; return handicap; }