Add shell option to auto-evaluate all game actions

This commit is contained in:
Maximilian Keßler 2024-03-05 22:46:51 +01:00
parent 9af42a43a4
commit fd4f080d07
Signed by: max
GPG Key ID: BCC5A619923C0BA5

View File

@ -30,9 +30,9 @@ namespace Hanabi
return ret;
}
const static std::array<std::string, 13> cli_commands = {
const static std::array<std::string, 14> cli_commands = {
"play", "clue", "discard", "opt", "state", "id", "revert", "actions", "evaluate", "help", "quit", "set-initials"
, "dump-id-parts",
, "dump-id-parts", "toggle-auto-evaluation"
};
char *cli_commands_generator(const char *text, int state)
@ -192,6 +192,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;
while (true)
{
@ -200,26 +201,26 @@ namespace Hanabi
if (prompt.find("help") == 0)
{
std::cout << "state: print information on current game state." << std::endl;
std::cout << "clue: give a clue." << std::endl;
std::cout << "play <card>: play specified card." << std::endl;
std::cout << "discard: discard trash from hand." << std::endl;
std::cout
<< "opt: take optimal action. In case of ties, prefers plays and discards in that order."
<< std::endl;
std::cout << "revert <turns>: revert specified number of turns (default 1)." << std::endl;
std::cout << "actions: display list of reasonable actions to take and their winning chances."
std::cout << "state: print information on current game state." << std::endl;
std::cout << "clue: give a clue." << std::endl;
std::cout << "play <card>: play specified card." << std::endl;
std::cout << "discard: discard trash from hand." << std::endl;
std::cout << "opt: take optimal action. In case of ties, prefers plays and discards in that order."
<< std::endl;
std::cout << "evaluate: evaluate current game state recursively. Potentially runtime-expensive."
std::cout << "revert <turns>: revert specified number of turns (default 1)." << std::endl;
std::cout << "actions: display list of reasonable actions to take and their winning chances."
<< 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."
std::cout << "evaluate: evaluate current game state recursively. Potentially runtime-expensive."
<< std::endl;
std::cout
<< "dump-id-parts: Dump parts used to calculate the id of the state as well as the cards associated to them."
<< std::endl;
std::cout << "help: Display this help message." << 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 << "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."
<< std::endl;
std::cout << "dump-id-parts: Dump parts used to calculate the id of the state as well as the cards associated to them."
<< std::endl;
std::cout << "help: Display this help message." << std::endl;
continue;
}
@ -284,6 +285,13 @@ namespace Hanabi
continue;
}
if (prompt.find("toggle-auto-evaluation") == 0)
{
evaluate_actions_on_query = !evaluate_actions_on_query;
std::cout << "Toggled auto-evaluation, now set to " << std::boolalpha << evaluate_actions_on_query << "." << std::endl;
continue;
}
if (prompt.find("revert") == 0)
{
if (depth == 0)
@ -397,7 +405,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();
std::vector<std::pair<Hanabi::Action, std::optional<Hanabi::probability_t>>> reasonable_actions = game.state->get_reasonable_actions(evaluate_actions_on_query);
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){