aboutsummaryrefslogtreecommitdiff
path: root/src/main/input-output/input/json-parsing
diff options
context:
space:
mode:
authorCharlie Blake2018-03-21 11:03:00 +0000
committerGitHub2018-03-21 11:03:00 +0000
commit58118e89351e4c82fb1f54ebb021a1b0f9ba3ff8 (patch)
tree559310dd2c48ed7db6af82233c5bf185d234ee30 /src/main/input-output/input/json-parsing
parentMerge pull request #43 from thecharlesblake/shortest-solution (diff)
parentUpdate benchmark spider scaling for correct rules (diff)
downloadmetasol-58118e89351e4c82fb1f54ebb021a1b0f9ba3ff8.tar.gz
metasol-58118e89351e4c82fb1f54ebb021a1b0f9ba3ff8.zip

Merge pull request #44 from thecharlesblake/spider-fix

Spider fix

Diffstat (limited to 'src/main/input-output/input/json-parsing')
-rw-r--r--src/main/input-output/input/json-parsing/rules_parser.cpp45
1 files changed, 39 insertions, 6 deletions
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 395f2e7..6fa89bc 100644
--- a/src/main/input-output/input/json-parsing/rules_parser.cpp
+++ b/src/main/input-output/input/json-parsing/rules_parser.cpp
@@ -56,7 +56,6 @@ sol_rules rules_parser::get_default() {
}
void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
-
if (!d.IsObject()) {
json_helper::json_parse_err("JSON doc must be object");
}
@@ -109,7 +108,7 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
} else {
- json_helper::json_parse_err("[tableau piles][spaces policy] must be an string");
+ json_helper::json_parse_err("[tableau piles][spaces policy] must be a string");
}
}
@@ -121,6 +120,28 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
+ if (d["tableau piles"].HasMember("move built group policy")) {
+ if (d["tableau piles"]["move built group policy"].IsString()) {
+ string mbgp_str = d["tableau piles"]["move built group policy"].GetString();
+
+ if (mbgp_str == "same-as-build") {
+ sr.built_group_pol = sr.build_pol;
+ } else if (mbgp_str == "any-suit") {
+ sr.built_group_pol = pol::ANY_SUIT;
+ } else if (mbgp_str == "red-black") {
+ sr.built_group_pol = pol::RED_BLACK;
+ } else if (mbgp_str == "same-suit") {
+ sr.built_group_pol = pol::SAME_SUIT;
+ } else if (mbgp_str == "no-build") {
+ sr.built_group_pol = pol::NO_BUILD;
+ } else {
+ json_helper::json_parse_err("[tableau piles][move built group policy] is invalid");
+ }
+ } else {
+ json_helper::json_parse_err("[tableau piles][move built group policy] must be a string");
+ }
+ }
+
if (d["tableau piles"].HasMember("diagonal deal")) {
if (d["tableau piles"]["diagonal deal"].IsBool()) {
sr.diagonal_deal = d["tableau piles"]["diagonal deal"].GetBool();
@@ -169,10 +190,6 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
- if (!sr.hole && !sr.foundations) {
- json_helper::json_parse_err("one of [hole] and [foundations] must be true");
- }
-
if (d.HasMember("foundations initial card")) {
if (d["foundations initial card"].IsBool()) {
sr.foundations_init_card = d["foundations initial card"].GetBool();
@@ -189,6 +206,14 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
+ if (d.HasMember("foundations complete piles")) {
+ if (d["foundations complete piles"].IsBool()) {
+ sr.foundations_comp_piles = d["foundations complete piles"].GetBool();
+ } else {
+ json_helper::json_parse_err("[foundations complete piles] must be a boolean");
+ }
+ }
+
if (d.HasMember("cells")) {
if (d["cells"].IsInt()) {
sr.cells = static_cast<uint8_t>(d["cells"].GetInt());
@@ -232,4 +257,12 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
json_helper::json_parse_err("[reserve stacked] must be a boolean");
}
}
+
+ int solution_types = 0;
+ if (sr.hole) solution_types++;
+ if (sr.foundations) solution_types++;
+ if (solution_types != 1) {
+ json_helper::json_parse_err("one and only one of [hole] and [foundations] "
+ "must be true");
+ }
}