From fd4f080d07c7c87a0a81398c80df6b424b6999f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 5 Mar 2024 22:46:51 +0100 Subject: [PATCH] Add shell option to auto-evaluate all game actions --- src/state_explorer.cpp | 48 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/state_explorer.cpp b/src/state_explorer.cpp index 331f7b6..07b92c6 100644 --- a/src/state_explorer.cpp +++ b/src/state_explorer.cpp @@ -30,9 +30,9 @@ namespace Hanabi return ret; } - const static std::array cli_commands = { + const static std::array 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 : 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 : 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 : 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 : 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 : 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 : 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>> reasonable_actions = game.state->get_reasonable_actions(); + std::vector>> reasonable_actions = game.state->get_reasonable_actions(evaluate_actions_on_query); std::sort(reasonable_actions.begin(), reasonable_actions.end(), [](std::pair> const & left, std::pair> const & right){