respect option on whether to start interactive shell
This commit is contained in:
parent
2debafe5d6
commit
c40aae3c4b
1 changed files with 13 additions and 18 deletions
21
src/main.cpp
21
src/main.cpp
|
@ -11,7 +11,8 @@
|
|||
|
||||
|
||||
namespace Hanabi {
|
||||
void analyze_game_and_start_cli(std::variant<int, const char*> game_id, int turn, std::optional<uint8_t> score_goal) {
|
||||
void analyze_game_and_start_cli(std::variant<int, const char*> game_id, int turn, std::optional<uint8_t> 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<std::chrono::milliseconds>(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;
|
||||
|
||||
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<HanabiStateIF>(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,6 +51,7 @@ namespace Hanabi {
|
|||
int main(int argc, char *argv[]) {
|
||||
int turn;
|
||||
std::optional<int> 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<std::string>(), "Input file containing game in hanab.live json format")
|
||||
("turn,t", boost::program_options::value<int>(&turn)->default_value(1), "Turn number of state to analyze. Turn 1 means no actions have been taken.")
|
||||
("score,s", boost::program_options::value<int>(), "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<bool>(&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<std::string>().c_str(), turn, score);
|
||||
Hanabi::analyze_game_and_start_cli(vm["file"].as<std::string>().c_str(), turn, score, interactive_shell);
|
||||
} else {
|
||||
Hanabi::analyze_game_and_start_cli(vm["id"].as<int>(), turn, score);
|
||||
Hanabi::analyze_game_and_start_cli(vm["id"].as<int>(), turn, score, interactive_shell);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue