Add option to list all actions, even unreasonable ones

This commit is contained in:
Maximilian Keßler 2024-03-05 22:51:54 +01:00
parent fd4f080d07
commit 60c405fa20
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -30,9 +30,9 @@ namespace Hanabi
return ret;
}
const static std::array<std::string, 14> cli_commands = {
const static std::array<std::string, 15> cli_commands = {
"play", "clue", "discard", "opt", "state", "id", "revert", "actions", "evaluate", "help", "quit", "set-initials"
, "dump-id-parts", "toggle-auto-evaluation"
, "dump-id-parts", "toggle-auto-evaluation", "toggle-reasonable-actions"
};
char *cli_commands_generator(const char *text, int state)
@ -193,6 +193,7 @@ namespace Hanabi
// Tracks the depth of the replay the user explores. We have to ensure that we don't revert too much.
unsigned depth = 0;
bool evaluate_actions_on_query = false;
bool show_only_reasonable_actions = true;
while (true)
{
@ -214,6 +215,8 @@ namespace Hanabi
<< std::endl;
std::cout << "toggle-auto-evaluation: If set to true, all available game actions will be evaluated upon listing them. "
<< "Currently set to " << std::boolalpha << evaluate_actions_on_query << "." << std::endl;
std::cout << "toggle-reasonable-actions: If set to true, only reasonable actions will be suggested. "
<< "Currently set to " << std::boolalpha << show_only_reasonable_actions << "." << std::endl;
std::cout << "set-initials <chars>: Set initials for the suits." << std::endl;
std::cout << "(q)uit: Quit this interactive shell." << std::endl;
std::cout << "id: display id of state. Has no inherent meaning, useful for debugging."
@ -292,6 +295,13 @@ namespace Hanabi
continue;
}
if (prompt.find("toggle-reasonable-actions") == 0)
{
show_only_reasonable_actions = !show_only_reasonable_actions;
std::cout << "Toggled showing only reasonable actions, now set to " << std::boolalpha << show_only_reasonable_actions << "." << std::endl;
continue;
}
if (prompt.find("revert") == 0)
{
if (depth == 0)
@ -405,7 +415,7 @@ namespace Hanabi
if (prompt.find("actions") == 0)
{
std::vector<std::pair<Hanabi::Action, std::optional<Hanabi::probability_t>>> reasonable_actions = game.state->get_reasonable_actions(evaluate_actions_on_query);
std::vector<std::pair<Hanabi::Action, std::optional<Hanabi::probability_t>>> reasonable_actions = game.state->get_reasonable_actions(evaluate_actions_on_query, show_only_reasonable_actions);
std::sort(reasonable_actions.begin(), reasonable_actions.end(),
[](std::pair<Hanabi::Action, std::optional<probability_t>> const & left,
std::pair<Hanabi::Action, std::optional<probability_t>> const & right){