add command line option to print all future game states as well
This commit is contained in:
parent
6dd2b07c09
commit
acece2a952
1 changed files with 27 additions and 9 deletions
26
src/main.cpp
26
src/main.cpp
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace Hanabi {
|
||||
void analyze_game_and_start_cli(std::variant<int, const char*> game_id, int turn, int draw_pile_size, std::optional<uint8_t> score_goal,
|
||||
bool start_cli) {
|
||||
bool start_cli, bool print_remaining_states, bool quiet) {
|
||||
auto game = Download::get_game(game_id, score_goal);
|
||||
if (game.state == nullptr) {
|
||||
if(game_id.index() == 0) {
|
||||
|
@ -25,19 +25,35 @@ namespace Hanabi {
|
|||
|
||||
game.forward_until(turn, draw_pile_size);
|
||||
|
||||
if (not quiet) {
|
||||
std::cout << "Analysing state: " << std::endl << std::endl << *game.state << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
game.state->init_backtracking_information();
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
auto res = game.state->evaluate_state();
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::cout.precision(10);
|
||||
std::cout << std::endl;
|
||||
if (not (quiet and print_remaining_states)) {
|
||||
std::cout << "Probability with optimal play: ";
|
||||
}
|
||||
print_probability(std::cout, res) << std::endl;
|
||||
if (not quiet) {
|
||||
std::cout << "Took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start) << "." << std::endl;
|
||||
std::cout << "Visited " << game.state->enumerated_states() << " states." << std::endl;
|
||||
std::cout << "Enumerated " << game.state->position_tablebase().size() << " unique game states. " << std::endl;
|
||||
}
|
||||
|
||||
if (print_remaining_states)
|
||||
{
|
||||
for(size_t remaining_cards = game.state->draw_pile_size(); remaining_cards > 0; remaining_cards--) {
|
||||
game.forward_until(100, remaining_cards);
|
||||
res = game.state->evaluate_state();
|
||||
std::cout << "Probability with " << remaining_cards << " cards left in deck: ";
|
||||
print_probability(std::cout, res) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (start_cli) {
|
||||
std::cout << std::endl;
|
||||
|
@ -66,6 +82,8 @@ int main(int argc, char *argv[]) {
|
|||
("draw,d", boost::program_options::value<int>(&draw_pile_size), "Draw pile size of state to analyze.")
|
||||
("score,s", boost::program_options::value<int>(), "Score that counts as a win, i.e. is optimized for achieving.")
|
||||
("interactive,i", boost::program_options::value<bool>(&interactive_shell)->default_value(true), "Drop into interactive shell to explore game")
|
||||
("remaining-states,r", "Print probabilities for all further sizes of draw pile.")
|
||||
("quiet,q", "Deactivate all non-essential prints")
|
||||
;
|
||||
boost::program_options::variables_map vm;
|
||||
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
|
||||
|
@ -93,9 +111,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, draw_pile_size, score, interactive_shell);
|
||||
Hanabi::analyze_game_and_start_cli(vm["file"].as<std::string>().c_str(), turn, draw_pile_size, score, interactive_shell, vm.count("remaining-states"), vm.count("quiet"));
|
||||
} else {
|
||||
Hanabi::analyze_game_and_start_cli(vm["id"].as<int>(), turn, draw_pile_size, score, interactive_shell);
|
||||
Hanabi::analyze_game_and_start_cli(vm["id"].as<int>(), turn, draw_pile_size, score, interactive_shell, vm.count("remaining-states"), vm.count("quiet"));
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue