aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorthecharlesblake2017-10-28 10:13:13 +0100
committerthecharlesblake2017-10-28 10:13:13 +0100
commit70522b28586ba117ff9e1e27c8f4b183f8414fd1 (patch)
tree7ab7edafbbec14406f876e2bca72b0eb69411b26 /src
parentAdd random game generation to bh (diff)
downloadmetasol-70522b28586ba117ff9e1e27c8f4b183f8414fd1.tar.gz
metasol-70522b28586ba117ff9e1e27c8f4b183f8414fd1.zip

Add simple and regular bh types

Diffstat (limited to 'src')
-rw-r--r--src/main/command_line_helper.cpp21
-rw-r--r--src/main/command_line_helper.h1
-rw-r--r--src/main/game_state.cpp12
-rw-r--r--src/main/game_state.h6
-rw-r--r--src/main/main.cpp4
5 files changed, 35 insertions, 9 deletions
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 <vector>
#include <ostream>
+#include <string>
#include <rapidjson/document.h>
@@ -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<game_state> 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<std::vector<card> > 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";