From 8f6d8c68febe050b9a33fafaf4587ca98a9f5dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 11 Nov 2023 01:16:25 +0100 Subject: [PATCH] add option to analyze all different clue counts --- include/game_state.h | 2 ++ include/game_state.hpp | 7 +++++++ src/main.cpp | 31 +++++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/include/game_state.h b/include/game_state.h index 446adde..4b4aa95 100644 --- a/include/game_state.h +++ b/include/game_state.h @@ -221,6 +221,7 @@ public: virtual void revert() = 0; virtual void modify_clues(clue_t change) = 0; + virtual void set_clues(clue_t clues) = 0; [[nodiscard]] virtual player_t turn() const = 0; [[nodiscard]] virtual clue_t num_clues() const = 0; @@ -286,6 +287,7 @@ public: void revert() final; void modify_clues(clue_t change) final; + void set_clues(clue_t clues) final; [[nodiscard]] player_t turn() const final; [[nodiscard]] clue_t num_clues() const final; diff --git a/include/game_state.hpp b/include/game_state.hpp index 11b4d2e..e063bcc 100644 --- a/include/game_state.hpp +++ b/include/game_state.hpp @@ -524,6 +524,13 @@ namespace Hanabi { } } + template + void HanabiState::set_clues(Hanabi::clue_t clues) { + assert(0 <= clues); + assert(clues <= 8); + _num_clues = clues; + } + template player_t HanabiState::turn() const { return _turn; diff --git a/src/main.cpp b/src/main.cpp index 2ca672a..d4a0557 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,7 @@ namespace Hanabi { void analyze_game_and_start_cli(std::variant game_id, int turn, int draw_pile_size, std::optional score_goal, - bool start_cli, bool print_remaining_states, bool quiet, clue_t clue_modifier) { + bool start_cli, bool print_remaining_states, bool quiet, clue_t clue_modifier, bool all_clues) { auto game = Download::get_game(game_id, score_goal); if (game.state == nullptr) { if(game_id.index() == 0) { @@ -50,9 +50,21 @@ namespace Hanabi { { 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 (all_clues) { + clue_t original_num_clues = game.state->num_clues(); + for(clue_t num_clues = 0; num_clues <= 8; num_clues++) { + game.state->set_clues(num_clues); + res = game.state->evaluate_state(); + std::cout << "Probability with " << remaining_cards << " cards left in deck and " << +num_clues + << " clues (" << std::showpos << +(num_clues - original_num_clues) << "): " << std::noshowpos; + print_probability(std::cout, res) << std::endl; + } + game.state->set_clues(original_num_clues); + } else { + res = game.state->evaluate_state(); + std::cout << "Probability with " << remaining_cards << " cards left in deck: "; + print_probability(std::cout, res) << std::endl; + } } } @@ -86,6 +98,7 @@ int main(int argc, char *argv[]) { ("interactive,i", boost::program_options::value(&interactive_shell)->default_value(true), "Drop into interactive shell to explore game") ("remaining-states,r", "Print probabilities for all further sizes of draw pile.") ("clue-modifier,c", boost::program_options::value(&clue_modifier)->default_value(0), "Modification to the number of clues applied to selected game state.") + ("all-clues", "Solve instance for all clue counts in all positions") ("quiet,q", "Deactivate all non-essential prints") ; boost::program_options::variables_map vm; @@ -103,6 +116,12 @@ int main(int argc, char *argv[]) { return EXIT_SUCCESS; } + if (vm.count("remaining-states") and clue_modifier != 0) { + std::cout << "You cannot use a clue modifier and solve the remaining states, the further game progress might be impossible with modified clue count." << std::endl; + std::cout << "Use '--help' to print a help message." << std::endl; + return EXIT_SUCCESS; + } + if (vm.count("draw") + vm.count("turn") != 1) { std::cout << "Exactly one option of 'draw' and 'turn' has to be given." << std::endl; std::cout << "Use '--help' to print a help message." << std::endl; @@ -114,9 +133,9 @@ int main(int argc, char *argv[]) { } if (vm.count("file")) { - Hanabi::analyze_game_and_start_cli(vm["file"].as().c_str(), turn, draw_pile_size, score, interactive_shell, vm.count("remaining-states"), vm.count("quiet"), clue_modifier); + Hanabi::analyze_game_and_start_cli(vm["file"].as().c_str(), turn, draw_pile_size, score, interactive_shell, vm.count("remaining-states"), vm.count("quiet"), clue_modifier, vm.count("all-clues")); } else { - Hanabi::analyze_game_and_start_cli(vm["id"].as(), turn, draw_pile_size, score, interactive_shell, vm.count("remaining-states"), vm.count("quiet"), clue_modifier); + Hanabi::analyze_game_and_start_cli(vm["id"].as(), turn, draw_pile_size, score, interactive_shell, vm.count("remaining-states"), vm.count("quiet"), clue_modifier, vm.count("all-clues")); } return EXIT_SUCCESS; }