aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorthecharlesblake2017-11-11 11:55:19 +0000
committerthecharlesblake2017-11-11 11:55:19 +0000
commit8670a71468d0deb2bcd6d52d27873f9427c42ad9 (patch)
treeb01eb54901abb147925c1d1c5e6c1b3f66ee9e16 /src/main
parentAdd src file directory structure (diff)
downloadmetasol-8670a71468d0deb2bcd6d52d27873f9427c42ad9.tar.gz
metasol-8670a71468d0deb2bcd6d52d27873f9427c42ad9.zip

Refactor main

Diffstat (limited to 'src/main')
-rw-r--r--src/main/main.cpp49
1 files changed, 30 insertions, 19 deletions
diff --git a/src/main/main.cpp b/src/main/main.cpp
index 7a0d390..77d5d5b 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -14,6 +14,8 @@ using namespace std;
namespace po = boost::program_options;
+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&);
int main(int argc, const char* argv[]) {
@@ -26,31 +28,40 @@ int main(int argc, const char* argv[]) {
// Generates the rules of the solitaire from the game type
const sol_rules rules(clh.get_solitaire_type());
- int seed = clh.get_random_deal();
- if (seed >= 0) {
- cout << "Attempting to solve with seed: " << seed << "...\n";
- game_state gs(seed, rules);
- solve_game(gs, rules);
+ // Retrieves the input files to be solved
+ const vector<string> input_files = clh.get_input_files();
+
+ // 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);
+ }
+ // Otherwise, solve the input files
+ else {
+ solve_input_files(input_files, rules);
}
- for (auto input_json : clh.get_input_files()) {
- try {
- // Attempts to read the user's json into a document
- Document doc;
- deal_parser::parse(doc, input_json);
+ return 0;
+}
+
+void solve_random_game(int seed, const sol_rules& rules) {
+ cout << "Attempting to solve with seed: " << seed << "...\n";
+ game_state gs(seed, rules);
+ solve_game(gs, rules);
+}
- // Creates a game state object from the json, plus a solver
- game_state gs(doc);
+void solve_input_files(const vector<string> input_files, const sol_rules rules) {
+ for (const auto &input_json : input_files) {
+ // Attempts to read the user's json into a document
+ Document doc;
+ deal_parser::parse(doc, input_json);
- cout << "Attempting to solve " << input_json << "...\n";
- solve_game(gs, rules);
+ // Creates a game state object from the json, plus a solver
+ game_state gs(doc);
- } catch (runtime_error& e) {
- cerr << "Error: " << e.what() << "\n";
- }
+ cout << "Attempting to solve " << input_json << "...\n";
+ solve_game(gs, rules);
}
-
- return 0;
}
void solve_game(const game_state& gs, const sol_rules& rules) {