From 70522b28586ba117ff9e1e27c8f4b183f8414fd1 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 10:13:13 +0100 Subject: Add simple and regular bh types --- src/main/command_line_helper.cpp | 21 +++++++++++++++++++-- src/main/command_line_helper.h | 1 + src/main/game_state.cpp | 12 +++++++++--- src/main/game_state.h | 6 ++++-- src/main/main.cpp | 4 ++-- 5 files changed, 35 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/command_line_helper.cpp b/src/main/command_line_helper.cpp index 67bf7ff..fdf6c9c 100644 --- a/src/main/command_line_helper.cpp +++ b/src/main/command_line_helper.cpp @@ -75,18 +75,35 @@ bool command_line_helper::assess_errors() { return false; } - if (random_deal && !input_files.empty()) { + bool valid_sol_type = assess_sol_type(); + if (!valid_sol_type) return false; + + if (random_deal >= 0 && !input_files.empty()) { print_rand_plus_input_err(); return false; } - if (input_files.empty() && !random_deal) { + if (input_files.empty() && random_deal >= 0) { print_no_input_error(); return false; } return true; } +bool command_line_helper::assess_sol_type() { + if (solitaire_type == "black-hole") { + return true; + } else if (solitaire_type == "simple-black-hole") { + return true; + } else { + cerr << "Error: Solitaire type is not valid: " << solitaire_type + << "\nValid solitaire types are: 'black-hole' and " + "'simple-black-hole'"; + print_help(); + return false; + } +} + void command_line_helper::print_help() { cout << "Usage: solvitaire [options] input-file1 input-file2 ...\n" << main_options << "\n"; diff --git a/src/main/command_line_helper.h b/src/main/command_line_helper.h index 97c522a..5694830 100644 --- a/src/main/command_line_helper.h +++ b/src/main/command_line_helper.h @@ -17,6 +17,7 @@ public: bool get_help(); private: bool assess_errors(); + bool assess_sol_type(); void print_help(); void print_no_input_error(); void print_no_sol_type_error(); diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp index 527f080..ef9db97 100644 --- a/src/main/game_state.cpp +++ b/src/main/game_state.cpp @@ -16,7 +16,10 @@ using namespace rapidjson; using namespace std; // Construct an initial game state from a JSON doc -game_state::game_state(const Document& doc) : max_rank(1) { +game_state::game_state(const Document& doc, string sol_type) + : max_rank(1) { + simple = sol_type == "simple-black-hole"; + // Construct tableau piles assert(doc.HasMember("tableau piles")); const Value& json_tab_piles = doc["tableau piles"]; @@ -42,7 +45,10 @@ game_state::game_state(const Document& doc) : max_rank(1) { } // Construct an initial game state from a seed -game_state::game_state(int seed) : max_rank(7) { +game_state::game_state(int seed, string sol_type) { + simple = sol_type == "simple-black-hole"; + max_rank = simple ? 7 : 13; + int start = 1; // Ignore the first (hole) card int end = max_rank * 4; @@ -51,7 +57,7 @@ game_state::game_state(int seed) : max_rank(7) { for (int i = start; i < end; i++) { v.push_back(new int(i)); } - + // Randomly shuffle the pointers auto rng = std::default_random_engine(seed); std::shuffle(std::begin(v), std::end(v), rng); diff --git a/src/main/game_state.h b/src/main/game_state.h index d7a396f..ff92247 100644 --- a/src/main/game_state.h +++ b/src/main/game_state.h @@ -7,6 +7,7 @@ #include #include +#include #include @@ -14,8 +15,8 @@ class game_state { public: - game_state(const rapidjson::Document&); - game_state(int seed); + game_state(const rapidjson::Document&, std::string); + game_state(int seed, std::string); std::vector get_next_legal_states() const; bool is_solved() const; std::ostream& print(std::ostream&) const; @@ -25,6 +26,7 @@ public: private: void move_to_hole(int); bool adjacent(const card& a, const card& b) const; + bool simple; std::vector > tableau_piles; int max_rank; diff --git a/src/main/main.cpp b/src/main/main.cpp index ae5e00b..cc1df9f 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -24,7 +24,7 @@ int main(int argc, const char* argv[]) { int seed = clh.get_random_deal(); if (seed >= 0) { - game_state gs(seed); + game_state gs(seed, clh.get_solitaire_type()); solver sol(gs); cout << "Attempting to solve with seed: " << seed << "...\n"; @@ -39,7 +39,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); + game_state gs(doc, clh.get_solitaire_type()); solver sol(gs); cout << "Attempting to solve " << input_json << "...\n"; -- cgit v1.2.1