aboutsummaryrefslogtreecommitdiff
path: root/src/main/main.cpp
diff options
context:
space:
mode:
authorthecharlesblake2017-10-28 15:15:49 +0100
committerthecharlesblake2017-10-28 15:15:49 +0100
commitd472356d4e01c72e3b51deb28f694b9d0dd4fd6e (patch)
treecf0f84f8eb51227712566bcdd535185c74d2a094 /src/main/main.cpp
parentRefactor game generation to make more generic (diff)
downloadmetasol-d472356d4e01c72e3b51deb28f694b9d0dd4fd6e.tar.gz
metasol-d472356d4e01c72e3b51deb28f694b9d0dd4fd6e.zip

Add rules class to represent solitaire type

Diffstat (limited to 'src/main/main.cpp')
-rw-r--r--src/main/main.cpp24
1 files changed, 16 insertions, 8 deletions
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;
+}