diff options
| author | Charlie Blake | 2017-11-14 02:24:07 +0000 |
|---|---|---|
| committer | GitHub | 2017-11-14 02:24:07 +0000 |
| commit | 995ef52047458e1d59c396df7148ae55b7b93a3c (patch) | |
| tree | e2d76d46bb435d01760bb01db9e4123f33063a2d /src/main/main.cpp | |
| parent | Merge pull request #20 from thecharlesblake/initial-code-cleanup (diff) | |
| parent | Add logic for reading preset sols and file json (diff) | |
| download | metasol-995ef52047458e1d59c396df7148ae55b7b93a3c.tar.gz metasol-995ef52047458e1d59c396df7148ae55b7b93a3c.zip | |
Merge pull request #21 from thecharlesblake/json-rules
Json rules
Diffstat (limited to 'src/main/main.cpp')
| -rw-r--r-- | src/main/main.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/main/main.cpp b/src/main/main.cpp index d748c80..1d110ef 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -15,6 +15,7 @@ using namespace boost; namespace po = boost::program_options; +const optional<sol_rules> gen_rules(command_line_helper&); void solve_random_game(int, const sol_rules&); void solve_input_files(const vector<string>, const sol_rules); void solve_game(const game_state&, const sol_rules&); @@ -23,11 +24,12 @@ int main(int argc, const char* argv[]) { // Parses the command-line options command_line_helper clh; if (!clh.parse(argc, argv)) { - return 1; + return EXIT_FAILURE; } // Generates the rules of the solitaire from the game type - const sol_rules rules(clh.get_solitaire_type()); + const optional<sol_rules> rules = gen_rules(clh); + if (!rules) return EXIT_FAILURE; // Retrieves the input files to be solved const vector<string> input_files = clh.get_input_files(); @@ -35,14 +37,29 @@ int main(int argc, const char* argv[]) { // If there are no input files, solve a random deal based on the // supplied seed if (input_files.empty()) { - solve_random_game(clh.get_random_deal(), rules); + solve_random_game(clh.get_random_deal(), *rules); } // Otherwise, solve the input files else { - solve_input_files(input_files, rules); + solve_input_files(input_files, *rules); } - return 0; + return EXIT_SUCCESS; +} + +const optional<sol_rules> gen_rules(command_line_helper& clh) { + try { + if (!clh.get_solitaire_type().empty()) { + return sol_rules::from_preset(clh.get_solitaire_type()); + } else { + return sol_rules::from_file(clh.get_rules_file()); + } + } catch (const runtime_error& error) { + string errmsg = "Error in rules generation: "; + errmsg += error.what(); + LOG_ERROR(errmsg); + return none; + } } void solve_random_game(int seed, const sol_rules& rules) { |
