From 81fdc3f73a5d89e613c8e19f385c2144b35f6204 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 12:19:20 +0100 Subject: Add Spanish Paitence to cmd parse and refactor --- src/main/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index cc1df9f..245b737 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -4,7 +4,6 @@ #include #include "command_line_helper.h" -#include "card.h" #include "deal_parser.h" #include "game_state.h" #include "solver.h" -- cgit v1.2.1 From d472356d4e01c72e3b51deb28f694b9d0dd4fd6e Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 15:15:49 +0100 Subject: Add rules class to represent solitaire type --- src/main/main.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index 245b737..d39d35c 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -7,6 +7,7 @@ #include "deal_parser.h" #include "game_state.h" #include "solver.h" +#include "sol_rules.h" using namespace rapidjson; @@ -14,6 +15,8 @@ using namespace std; namespace po = boost::program_options; +void solve_game(const game_state&, const sol_rules&); + int main(int argc, const char* argv[]) { // Parses the command-line options command_line_helper clh; @@ -21,14 +24,14 @@ int main(int argc, const char* argv[]) { return 1; } + // 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) { - game_state gs(seed, clh.get_solitaire_type()); - solver sol(gs); - cout << "Attempting to solve with seed: " << seed << "...\n"; - sol.run(); - cout << sol; + game_state gs(seed, sol_rules); + solve_game(gs, sol_rules); } for (auto input_json : clh.get_input_files()) { @@ -39,11 +42,9 @@ int main(int argc, const char* argv[]) { // Creates a game state object from the json, plus a solver game_state gs(doc, clh.get_solitaire_type()); - solver sol(gs); cout << "Attempting to solve " << input_json << "...\n"; - sol.run(); - cout << sol; + solve_game(gs, sol_rules); } catch (runtime_error& e) { cerr << "Error: " << e.what() << "\n"; @@ -52,3 +53,10 @@ int main(int argc, const char* argv[]) { return 0; } + +void solve_game(const game_state& gs, const sol_rules& rules) { + solver sol(gs, rules); + + sol.run(); + cout << sol; +} -- cgit v1.2.1 From 6a5a840f678aa78659b51ec647dcced4544c4a0b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 15:29:17 +0100 Subject: Modify game state generation to work across sols --- src/main/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index d39d35c..65730d2 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -41,7 +41,7 @@ int main(int argc, const char* argv[]) { deal_parser::parse(doc, input_json); // Creates a game state object from the json, plus a solver - game_state gs(doc, clh.get_solitaire_type()); + game_state gs(doc); cout << "Attempting to solve " << input_json << "...\n"; solve_game(gs, sol_rules); -- cgit v1.2.1 From c2e0bbad760bb95b7967d6df065c46e1aac1270d Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 15:50:45 +0100 Subject: Add generic state printing --- src/main/main.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index 65730d2..5e11537 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -7,7 +7,6 @@ #include "deal_parser.h" #include "game_state.h" #include "solver.h" -#include "sol_rules.h" using namespace rapidjson; @@ -30,8 +29,8 @@ int main(int argc, const char* argv[]) { int seed = clh.get_random_deal(); if (seed >= 0) { cout << "Attempting to solve with seed: " << seed << "...\n"; - game_state gs(seed, sol_rules); - solve_game(gs, sol_rules); + game_state gs(seed, rules); + solve_game(gs, rules); } for (auto input_json : clh.get_input_files()) { @@ -44,7 +43,7 @@ int main(int argc, const char* argv[]) { game_state gs(doc); cout << "Attempting to solve " << input_json << "...\n"; - solve_game(gs, sol_rules); + solve_game(gs, rules); } catch (runtime_error& e) { cerr << "Error: " << e.what() << "\n"; -- cgit v1.2.1