aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/game/sol_rules.cpp8
-rw-r--r--src/main/game/sol_rules.h9
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.cpp14
-rw-r--r--src/main/input-output/input/json-parsing/rules_parser.cpp56
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp12
-rw-r--r--src/test/integration_tests/gaps_test.cpp8
6 files changed, 95 insertions, 12 deletions
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp
index d50d852..e9f4edf 100644
--- a/src/main/game/sol_rules.cpp
+++ b/src/main/game/sol_rules.cpp
@@ -7,6 +7,8 @@
typedef sol_rules::build_policy pol;
typedef sol_rules::spaces_policy s_pol;
typedef sol_rules::stock_deal_type sdt;
+typedef sol_rules::direction dir;
+typedef sol_rules::face_up_policy fu;
// Note that the 'default' sol rules are set up by parsing the default json
// rules description. This initialisation is really just for testing purposes.
@@ -28,5 +30,9 @@ sol_rules::sol_rules() :
stock_deal_t(sdt::TABLEAU_PILES),
stock_deal_count(1),
reserve_size(0),
- reserve_stacked(false) {
+ reserve_stacked(false),
+ face_up(fu::ALL),
+ sequence_count(0),
+ sequence_direction(dir::LEFT),
+ sequence_build_pol(pol::SAME_SUIT) {
}
diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h
index 8075821..b03d854 100644
--- a/src/main/game/sol_rules.h
+++ b/src/main/game/sol_rules.h
@@ -32,6 +32,11 @@ struct sol_rules {
ALL,
TOP_CARDS
};
+ enum class direction {
+ LEFT,
+ RIGHT,
+ BOTH
+ };
uint8_t tableau_pile_count;
build_policy build_pol;
@@ -54,7 +59,9 @@ struct sol_rules {
uint8_t reserve_size;
bool reserve_stacked;
face_up_policy face_up;
-
+ uint8_t sequence_count;
+ direction sequence_direction;
+ build_policy sequence_build_pol;
};
#endif //SOLVITAIRE_SOL_RULES_H
diff --git a/src/main/input-output/input/json-parsing/deal_parser.cpp b/src/main/input-output/input/json-parsing/deal_parser.cpp
index 5a6dff6..7ab2cd2 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.cpp
+++ b/src/main/input-output/input/json-parsing/deal_parser.cpp
@@ -78,7 +78,16 @@ string deal_parser::deal_schema_json() {
"definitions": {
"card": {"type": "string", "pattern": "^(([0-9]|1[0-3]|a|A|j|J|q|Q|k|K)(c|C|d|D|h|H|s|S))$"},
- "cardarray": {"type": "array", "items": {"$ref": "#/definitions/card"}}
+ "cardarray": {"type": "array", "items": {"$ref": "#/definitions/card"}},
+ "cardarraywithempty": {
+ "type": "array",
+ "items": {
+ "oneOf":[
+ {"$ref": "#/definitions/card"},
+ {"type": "string","enum": [""]}
+ ]
+ }
+ }
},
"type": "object", "properties": {
@@ -89,6 +98,9 @@ string deal_parser::deal_schema_json() {
"foundations": {
"type": "array", "items": {"$ref": "#/definitions/cardarray"}
},
+ "sequences": {
+ "type": "array", "items": {"$ref": "#/definitions/cardarraywithempty"}
+ },
"hole": {"$ref": "#/definitions/card"},
"stock": {"$ref": "#/definitions/cardarray"},
"waste": {"$ref": "#/definitions/cardarray"},
diff --git a/src/main/input-output/input/json-parsing/rules_parser.cpp b/src/main/input-output/input/json-parsing/rules_parser.cpp
index 55a414c..e3c4601 100644
--- a/src/main/input-output/input/json-parsing/rules_parser.cpp
+++ b/src/main/input-output/input/json-parsing/rules_parser.cpp
@@ -22,6 +22,7 @@ typedef sol_rules::build_policy pol;
typedef sol_rules::spaces_policy s_pol;
typedef sol_rules::stock_deal_type sdt;
typedef sol_rules::face_up_policy fu;
+typedef sol_rules::direction dir;
const sol_rules rules_parser::from_file(const string rules_file) {
sol_rules sr = get_default();
@@ -305,6 +306,56 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
+ if (d.HasMember("sequences")) {
+ if (d["sequences"].IsObject()) {
+ if (d["sequences"].HasMember("count")) {
+ if (d["sequences"]["count"].IsInt()) {
+ sr.sequence_count = static_cast<uint8_t>(d["sequences"]["count"].GetInt());
+ } else {
+ json_helper::json_parse_err("[count] must be an integer");
+ }
+ }
+
+ if (d["sequences"].HasMember("build policy")) {
+ if (d["sequences"]["build policy"].IsString()) {
+ string bp_str = d["sequences"]["build policy"].GetString();
+
+ if (bp_str == "any-suit") {
+ sr.sequence_build_pol = pol::ANY_SUIT;
+ } else if (bp_str == "red-black") {
+ sr.sequence_build_pol = pol::RED_BLACK;
+ } else if (bp_str == "same-suit") {
+ sr.sequence_build_pol = pol::SAME_SUIT;
+ } else {
+ json_helper::json_parse_err("[sequences][build policy] is invalid");
+ }
+ } else {
+ json_helper::json_parse_err("[sequences][build policy] must be an string");
+ }
+ }
+
+ if (d["sequences"].HasMember("direction")) {
+ if (d["sequences"]["direction"].IsString()) {
+ string dir_str = d["sequences"]["direction"].GetString();
+
+ if (dir_str == "L") {
+ sr.sequence_direction = dir::LEFT;
+ } else if (dir_str == "R") {
+ sr.sequence_direction = dir::RIGHT;
+ } else if (dir_str == "LR") {
+ sr.sequence_direction = dir::BOTH;
+ } else {
+ json_helper::json_parse_err("[sequences][direction] is invalid");
+ }
+ } else {
+ json_helper::json_parse_err("[sequences][direction] must be an string");
+ }
+ }
+ } else {
+ json_helper::json_parse_err("[sequences] must be an object");
+ }
+ }
+
if (d.HasMember("max rank")) {
if (d["max rank"].IsInt()) {
sr.max_rank = static_cast<card::rank_t>(d["max rank"].GetInt());
@@ -327,8 +378,9 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
int solution_types = 0;
if (sr.hole) solution_types++;
if (sr.foundations_present) solution_types++;
+ if (sr.sequence_count > 0) solution_types++;
if (solution_types != 1) {
- json_helper::json_parse_err("one and only one of [hole] and [foundations] "
+ json_helper::json_parse_err("one and only one of [hole], [foundations] and [sequences][count] > 0 "
"must be true");
}
@@ -462,7 +514,7 @@ string rules_parser::rules_schema_json() {
},
"additionalProperties": false
},
- "sequence": {
+ "sequences": {
"type": "object",
"properties": {
"count": {
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index 2e3083c..a004136 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -47,7 +47,7 @@ map<string, string> sol_preset_types::mp = {
"size": 0,
"stacked": false
},
- "sequence": {
+ "sequences": {
"count": 0,
"direction": "L",
"build policy": "same-suit"
@@ -1051,7 +1051,10 @@ map<string, string> sol_preset_types::mp = {
"foundations": {
"present": false
},
- "sequence": {
+ "tableau piles": {
+ "count": 0
+ },
+ "sequences": {
"count": 4,
"direction": "L",
"build policy": "same-suit"
@@ -1068,7 +1071,10 @@ map<string, string> sol_preset_types::mp = {
"foundations": {
"present": false
},
- "sequence": {
+ "tableau piles": {
+ "count": 0
+ },
+ "sequences": {
"count": 4,
"direction": "L",
"build policy": "same-suit"
diff --git a/src/test/integration_tests/gaps_test.cpp b/src/test/integration_tests/gaps_test.cpp
index 31f6d20..f7d0ebe 100644
--- a/src/test/integration_tests/gaps_test.cpp
+++ b/src/test/integration_tests/gaps_test.cpp
@@ -11,18 +11,18 @@ typedef test_helper th;
const static std::string path = "resources/gaps/";
const static std::string type = "simple-gaps";
-TEST(AlphaStar, SimpleSolvable) {
+TEST(Gaps, SimpleSolvable) {
EXPECT_TRUE(th::is_solvable(path + "SimpleSolvable.json", type));
}
-TEST(AlphaStar, ComplexSolvable) {
+TEST(Gaps, ComplexSolvable) {
EXPECT_TRUE(th::is_solvable(path + "ComplexSolvable.json", type));
}
-TEST(AlphaStar, SimpleUnsolvable) {
+TEST(Gaps, SimpleUnsolvable) {
EXPECT_FALSE(th::is_solvable(path + "SimpleUnsolvable.json", type));
}
-TEST(AlphaStar, ComplexUnsolvable) {
+TEST(Gaps, ComplexUnsolvable) {
EXPECT_FALSE(th::is_solvable(path + "ComplexUnsolvable.json", type));
}