diff --git a/src/main.cpp b/src/main.cpp index d61cde9..081cfa7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,8 @@ namespace Hanabi { - void analyze_game_and_start_cli(std::variant game_id, int turn, std::optional score_goal) { + void analyze_game_and_start_cli(std::variant game_id, int turn, std::optional score_goal, + bool start_cli) { auto game = Download::get_game(game_id, turn, 0, score_goal); if (game == nullptr) { if(game_id.index() == 0) { @@ -34,21 +35,14 @@ namespace Hanabi { std::cout << "Took " << std::chrono::duration_cast(end - start) << "." << std::endl; std::cout << "Visited " << game->enumerated_states() << " states." << std::endl; std::cout << "Enumerated " << game->position_tablebase().size() << " unique game states. " << std::endl; - std::cout << std::endl; - std::cout << "Dropping into interactive command line to explore result (type 'help'):" << std::endl; - auto game_shared = std::shared_ptr(game.release()); - auto states = game_shared->possible_next_states(0, false); - cli(game_shared); - } - - void print_usage(const char* program_name) { - std::cout << "Usage: " << program_name << "(GAME_ID | GAME_FILE) TURN [SCORE_GOAL]" << std::endl; - std::cout << " GAME_ID A game id from hanab.live" << std::endl; - std::cout << " GAME_FILE A path to a file describing the game in hanab.live json format." << std::endl; - std::cout << " TURN Turn number of state to analyze. Turn 1 means no actions have been taken." << std::endl; - std::cout << " TURN Turn number of state to analyze. Turn 1 means no actions have been taken." << std::endl; - std::cout << " SCORE_GOAL Score that counts as a win, i.e. is optimized for achieving." << std::endl; + if (start_cli) { + std::cout << std::endl; + std::cout << "Dropping into interactive command line to explore result (type 'help'):" << std::endl; + auto game_shared = std::shared_ptr(game.release()); + auto states = game_shared->possible_next_states(0, false); + cli(game_shared); + } } } @@ -57,6 +51,7 @@ namespace Hanabi { int main(int argc, char *argv[]) { int turn; std::optional score; + bool interactive_shell; boost::program_options::options_description desc("Allowed options"); desc.add_options() @@ -65,7 +60,7 @@ int main(int argc, char *argv[]) { ("file,f", boost::program_options::value(), "Input file containing game in hanab.live json format") ("turn,t", boost::program_options::value(&turn)->default_value(1), "Turn number of state to analyze. Turn 1 means no actions have been taken.") ("score,s", boost::program_options::value(), "Score that counts as a win, i.e. is optimized for achieving.") - ("interactive,i", "Drop into interactive shell to explore game") + ("interactive,i", boost::program_options::value(&interactive_shell)->default_value(true), "Drop into interactive shell to explore game") ; boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); @@ -87,9 +82,9 @@ int main(int argc, char *argv[]) { } if (vm.count("file")) { - Hanabi::analyze_game_and_start_cli(vm["file"].as().c_str(), turn, score); + Hanabi::analyze_game_and_start_cli(vm["file"].as().c_str(), turn, score, interactive_shell); } else { - Hanabi::analyze_game_and_start_cli(vm["id"].as(), turn, score); + Hanabi::analyze_game_and_start_cli(vm["id"].as(), turn, score, interactive_shell); } return EXIT_SUCCESS; }