diff options
Diffstat (limited to 'src/main/input-output/input')
| -rw-r--r-- | src/main/input-output/input/command_line_helper.cpp | 61 | ||||
| -rw-r--r-- | src/main/input-output/input/command_line_helper.h | 10 |
2 files changed, 64 insertions, 7 deletions
diff --git a/src/main/input-output/input/command_line_helper.cpp b/src/main/input-output/input/command_line_helper.cpp index ec9a375..67224d2 100644 --- a/src/main/input-output/input/command_line_helper.cpp +++ b/src/main/input-output/input/command_line_helper.cpp @@ -49,9 +49,12 @@ command_line_helper::command_line_helper() "Syntax: [sol unsol intract in-progress-1 in-progress-2 ...]") ("cores", po::value<uint>(), "the number of cores for the solvability percentages to be run across. " "Must be supplied with the solvability option.") - ("streamliners", "applies any relevant streamliners to the search. If the --solvability option is supplied," - " runs the streamliner version of the search first and then if unsuccessful, the full" - " search for each seed.") + ("streamliners", po::value<string>(), + "Applies streamliners to the search. Options include 'none', 'both', 'suit-symmetry'," + " 'auto-foundations', and 'smart-solvability'. Defaults to 'none', unless '--solvability' is" + " also supplied, in which case defaults to 'smart-solvability'. 'smart-solvability' mode is only" + " available with '--solvability', and runs first with both streamliners and a 10% timeout. If this" + " is unsuccessful (unsolvable or timeout), then runs again without streamliners.") ("benchmark", "outputs performance statistics for the solver on the " "supplied solitaire game. Must supply " "either 'random', 'benchmark', 'solvability' or list of deals to be " @@ -143,7 +146,29 @@ bool command_line_helper::parse(int argc, const char* argv[]) { for (uint i = 0; i < cores; i++) resume.push_back(i); } - streamliners = (vm.count("streamliners") != 0); + if (vm.count("streamliners")) { + auto& s = vm["streamliners"].as<string>(); + + if (s == "auto-foundations" ) streamliners = streamliner_opt::AUTO_FOUNDATIONS; + else if (s == "suit-symmetry") streamliners = streamliner_opt::SUIT_SYMMETRY; + else if (s == "both") streamliners = streamliner_opt::BOTH; + else if (s == "smart-solvability") { + if (solvability == -1) { + print_streamliner_solvability_error(); + return false; + } else { + streamliners = streamliner_opt::SMART; + } + } + else if (s == "none") streamliners = streamliner_opt::NONE; + else { + print_streamliner_error(s); + return false; + } + } else { + if (solvability == -1) streamliners = streamliner_opt::NONE; + else streamliners = streamliner_opt::SMART; + } benchmark = (vm.count("benchmark") != 0); @@ -230,6 +255,15 @@ void command_line_helper::print_resume_error() { print_help(); } +void command_line_helper::print_streamliner_error(const string& str) { + LOG_ERROR ("Error: invalid streamliner: " + str + ".\nAvailable options are: 'none', 'both', 'suit-symmetry'," + " 'auto-foundations', and 'smart-solvability'"); +} + +void command_line_helper::print_streamliner_solvability_error() { + LOG_ERROR ("Smart streamliner mode can only be used with '--solvability'"); +} + const vector<string> command_line_helper::get_input_files() { return input_files; } @@ -282,6 +316,23 @@ bool command_line_helper::get_benchmark() { return benchmark; } -bool command_line_helper::get_streamliners() { +command_line_helper::streamliner_opt command_line_helper::get_streamliners() { return streamliners; } + +game_state::streamliner_options command_line_helper::get_streamliners_game_state() { + return convert_streamliners(streamliners); +} + +game_state::streamliner_options command_line_helper::convert_streamliners(streamliner_opt so) { + switch (so){ + case command_line_helper::streamliner_opt::NONE: return game_state::streamliner_options::NONE; + case command_line_helper::streamliner_opt::AUTO_FOUNDATIONS: return game_state::streamliner_options::AUTO_FOUNDATIONS; + case command_line_helper::streamliner_opt::SUIT_SYMMETRY: return game_state::streamliner_options::SUIT_SYMMETRY; + case command_line_helper::streamliner_opt::BOTH: return game_state::streamliner_options::BOTH; + case command_line_helper::streamliner_opt::SMART: + default: + assert(false); + return game_state::streamliner_options::NONE;; + } +} diff --git a/src/main/input-output/input/command_line_helper.h b/src/main/input-output/input/command_line_helper.h index c12bb69..862e39f 100644 --- a/src/main/input-output/input/command_line_helper.h +++ b/src/main/input-output/input/command_line_helper.h @@ -6,10 +6,12 @@ #define SOLVITAIRE_COMMAND_LINE_HELPER_H #include <boost/program_options.hpp> +#include "../../game/search-state/game_state.h" class command_line_helper { public: command_line_helper(); + enum class streamliner_opt {NONE, AUTO_FOUNDATIONS, SUIT_SYMMETRY, BOTH, SMART}; bool parse(int argc, const char* argv[]); const std::vector<std::string> get_input_files(); @@ -21,11 +23,13 @@ public: uint get_cores(); bool get_available_game_types(); bool get_benchmark(); - bool get_streamliners(); + streamliner_opt get_streamliners(); + game_state::streamliner_options get_streamliners_game_state(); std::vector<int> get_resume(); uint64_t get_cache_capacity(); std::string get_describe_game_rules(); uint64_t get_timeout(); + static game_state::streamliner_options convert_streamliners(streamliner_opt); private: bool assess_errors(); @@ -35,6 +39,8 @@ private: void print_no_opts_error(); void print_too_many_opts_error(); void print_resume_error(); + void print_streamliner_error(const std::string&); + void print_streamliner_solvability_error(); boost::program_options::options_description cmdline_options; boost::program_options::options_description main_options; @@ -52,7 +58,7 @@ private: uint cores; bool available_game_types; bool benchmark; - bool streamliners; + streamliner_opt streamliners; uint64_t cache_capacity; uint64_t timeout; }; |
