add option to analyze all different clue counts
This commit is contained in:
parent
280833ff1f
commit
8f6d8c68fe
3 changed files with 34 additions and 6 deletions
|
@ -221,6 +221,7 @@ public:
|
||||||
virtual void revert() = 0;
|
virtual void revert() = 0;
|
||||||
|
|
||||||
virtual void modify_clues(clue_t change) = 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 player_t turn() const = 0;
|
||||||
[[nodiscard]] virtual clue_t num_clues() const = 0;
|
[[nodiscard]] virtual clue_t num_clues() const = 0;
|
||||||
|
@ -286,6 +287,7 @@ public:
|
||||||
void revert() final;
|
void revert() final;
|
||||||
|
|
||||||
void modify_clues(clue_t change) final;
|
void modify_clues(clue_t change) final;
|
||||||
|
void set_clues(clue_t clues) final;
|
||||||
|
|
||||||
[[nodiscard]] player_t turn() const final;
|
[[nodiscard]] player_t turn() const final;
|
||||||
[[nodiscard]] clue_t num_clues() const final;
|
[[nodiscard]] clue_t num_clues() const final;
|
||||||
|
|
|
@ -524,6 +524,13 @@ namespace Hanabi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
||||||
|
void HanabiState<num_suits, num_players, hand_size>::set_clues(Hanabi::clue_t clues) {
|
||||||
|
assert(0 <= clues);
|
||||||
|
assert(clues <= 8);
|
||||||
|
_num_clues = clues;
|
||||||
|
}
|
||||||
|
|
||||||
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
||||||
player_t HanabiState<num_suits, num_players, hand_size>::turn() const {
|
player_t HanabiState<num_suits, num_players, hand_size>::turn() const {
|
||||||
return _turn;
|
return _turn;
|
||||||
|
|
25
src/main.cpp
25
src/main.cpp
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
namespace Hanabi {
|
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,
|
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 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);
|
auto game = Download::get_game(game_id, score_goal);
|
||||||
if (game.state == nullptr) {
|
if (game.state == nullptr) {
|
||||||
if(game_id.index() == 0) {
|
if(game_id.index() == 0) {
|
||||||
|
@ -50,11 +50,23 @@ namespace Hanabi {
|
||||||
{
|
{
|
||||||
for(size_t remaining_cards = game.state->draw_pile_size(); remaining_cards > 0; remaining_cards--) {
|
for(size_t remaining_cards = game.state->draw_pile_size(); remaining_cards > 0; remaining_cards--) {
|
||||||
game.forward_until(100, remaining_cards);
|
game.forward_until(100, remaining_cards);
|
||||||
|
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();
|
res = game.state->evaluate_state();
|
||||||
std::cout << "Probability with " << remaining_cards << " cards left in deck: ";
|
std::cout << "Probability with " << remaining_cards << " cards left in deck: ";
|
||||||
print_probability(std::cout, res) << std::endl;
|
print_probability(std::cout, res) << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (start_cli) {
|
if (start_cli) {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
@ -86,6 +98,7 @@ int main(int argc, char *argv[]) {
|
||||||
("interactive,i", boost::program_options::value<bool>(&interactive_shell)->default_value(true), "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")
|
||||||
("remaining-states,r", "Print probabilities for all further sizes of draw pile.")
|
("remaining-states,r", "Print probabilities for all further sizes of draw pile.")
|
||||||
("clue-modifier,c", boost::program_options::value<int>(&clue_modifier)->default_value(0), "Modification to the number of clues applied to selected game state.")
|
("clue-modifier,c", boost::program_options::value<int>(&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")
|
("quiet,q", "Deactivate all non-essential prints")
|
||||||
;
|
;
|
||||||
boost::program_options::variables_map vm;
|
boost::program_options::variables_map vm;
|
||||||
|
@ -103,6 +116,12 @@ int main(int argc, char *argv[]) {
|
||||||
return EXIT_SUCCESS;
|
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) {
|
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 << "Exactly one option of 'draw' and 'turn' has to be given." << std::endl;
|
||||||
std::cout << "Use '--help' to print a help message." << 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")) {
|
if (vm.count("file")) {
|
||||||
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"), clue_modifier);
|
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"), clue_modifier, vm.count("all-clues"));
|
||||||
} else {
|
} else {
|
||||||
Hanabi::analyze_game_and_start_cli(vm["id"].as<int>(), 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<int>(), turn, draw_pile_size, score, interactive_shell, vm.count("remaining-states"), vm.count("quiet"), clue_modifier, vm.count("all-clues"));
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue