aboutsummaryrefslogtreecommitdiff
path: root/src/main/input-output/input
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/input-output/input')
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.cpp28
-rw-r--r--src/main/input-output/input/json-parsing/rules_parser.cpp94
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp90
3 files changed, 147 insertions, 65 deletions
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 7b8cf18..e5ecae2 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.cpp
+++ b/src/main/input-output/input/json-parsing/deal_parser.cpp
@@ -13,6 +13,7 @@ using namespace rapidjson;
typedef sol_rules::build_policy pol;
typedef sol_rules::stock_deal_type sdt;
typedef sol_rules::face_up_policy fu;
+typedef sol_rules::foundations_init_type fit;
void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) {
// There are two stages to reading in the supplied deal. It is both put
@@ -65,7 +66,7 @@ void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) {
if (gs.rules.foundations_present) {
bool supplied_foundations = parse_foundations(gs, doc);
- if (!supplied_foundations && gs.rules.foundations_init_card) {
+ if (!supplied_foundations && gs.rules.foundations_init_cards == fit::ALL) {
fill_foundations(gs);
}
}
@@ -105,9 +106,7 @@ string deal_parser::deal_schema_json() {
"tableau piles": {
"type": "array", "items": {"$ref": "#/definitions/cardarray"}
},
- "foundations": {
- "type": "array", "items": {"$ref": "#/definitions/cardarray"}
- },
+ "foundations": {"$ref": "#/definitions/cardarray"},
"sequences": {
"type": "array", "items": {"$ref": "#/definitions/cardarraywithempty"}
},
@@ -208,10 +207,6 @@ void deal_parser::parse_reserve(game_state &gs, const Document& doc) {
// We treat a regular reserve like multiple single-card piles,
// but a stacked reserve as a single multiple-card pile
- if (json_reserve_piles.Size() != gs.rules.reserve_size) {
- json_helper::json_parse_err("Incorrect reserve size");
- }
-
for (pile::ref i = 0; i < json_card_arr.Size(); i++) {
assert(json_card_arr[i].IsString());
pile::ref pr = gs.original_reserve[0];
@@ -269,17 +264,16 @@ bool deal_parser::parse_foundations(game_state &gs, const rapidjson::Document& d
const Value& json_foundations = doc["foundations"];
assert(json_foundations.IsArray());
- if (json_foundations.Size() != 4 * (gs.rules.two_decks ? 2 : 1) ) {
- json_helper::json_parse_err("Incorrect number of foundations");
- }
-
for (auto j = begin(json_foundations.GetArray()); j != end(json_foundations.GetArray()); j++) {
+ assert(j->IsString());
+ card c = card(j->GetString());
+ gs.place_card(gs.foundations[c.get_suit()], c);
+ }
- for (auto& json_card : j->GetArray()) {
- assert(json_card.IsString());
- card c = card(json_card.GetString());
- gs.place_card(gs.foundations[c.get_suit()], c);
- }
+ // If the game uses a random base for foundations, assume that the first card in the first foundation is that base
+ if (!gs.rules.foundations_base) {
+ auto& first_found = gs.piles[gs.foundations[0]];
+ gs.foundations_base = first_found[first_found.size() - 1].get_rank();
}
return true;
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 b70abdf..209153f 100644
--- a/src/main/input-output/input/json-parsing/rules_parser.cpp
+++ b/src/main/input-output/input/json-parsing/rules_parser.cpp
@@ -5,6 +5,8 @@
#include <vector>
#include <algorithm>
+#include "../../../../../lib/rapidjson/error/en.h"
+
#include "rules_parser.h"
#include "json_helper.h"
#include "../sol_preset_types.h"
@@ -24,6 +26,8 @@ typedef sol_rules::accordion_policy acc_pol;
typedef sol_rules::stock_deal_type sdt;
typedef sol_rules::face_up_policy fu;
typedef sol_rules::direction dir;
+typedef sol_rules::built_group_type bgt;
+typedef sol_rules::foundations_init_type fit;
const sol_rules rules_parser::from_file(const string rules_file) {
sol_rules sr = get_default();
@@ -115,6 +119,8 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
sr.spaces_pol = s_pol::NO_BUILD;
} else if (sp_str == "kings") {
sr.spaces_pol = s_pol::KINGS;
+ } else if (sp_str == "auto-reserve-then-waste") {
+ sr.spaces_pol = s_pol::AUTO_RESERVE_THEN_WASTE;
} else {
json_helper::json_parse_err("[tableau piles][spaces policy] is invalid");
}
@@ -125,10 +131,20 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
if (d["tableau piles"].HasMember("move built group")) {
- if (d["tableau piles"]["move built group"].IsBool()) {
- sr.move_built_group = d["tableau piles"]["move built group"].GetBool();
+ if (d["tableau piles"]["move built group"].IsString()) {
+ string mbg_str = d["tableau piles"]["move built group"].GetString();
+
+ if (mbg_str == "yes") {
+ sr.move_built_group = bgt::YES;
+ } else if (mbg_str == "no") {
+ sr.move_built_group = bgt::NO;
+ } else if (mbg_str == "whole-pile") {
+ sr.move_built_group = bgt::WHOLE_PILE;
+ } else {
+ json_helper::json_parse_err("[tableau piles][move built group] is invalid");
+ }
} else {
- json_helper::json_parse_err("[tableau piles][move built group] must be a boolean");
+ json_helper::json_parse_err("[tableau piles][move built group] must be a string");
}
}
@@ -183,6 +199,14 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
+ if (d["tableau piles"].HasMember("wraps")) {
+ if (d["tableau piles"]["wraps"].IsBool()) {
+ sr.tableau_wraps = d["tableau piles"]["wraps"].GetBool();
+ } else {
+ json_helper::json_parse_err("[tableau piles][wraps] must be a boolean");
+ }
+ }
+
} else {
json_helper::json_parse_err("[tableau piles] must be an object");
}
@@ -198,11 +222,37 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
- if (d["foundations"].HasMember("initial card")) {
- if (d["foundations"]["initial card"].IsBool()) {
- sr.foundations_init_card = d["foundations"]["initial card"].GetBool();
+ if (d["foundations"].HasMember("initial cards")) {
+ if (d["foundations"]["initial cards"].IsString()) {
+ string ic_str = d["foundations"]["initial cards"].GetString();
+
+ if (ic_str == "none") {
+ sr.foundations_init_cards = fit::NONE;
+ } else if (ic_str == "one") {
+ sr.foundations_init_cards = fit::ONE;
+ } else if (ic_str == "all") {
+ sr.foundations_init_cards = fit::ALL;
+ } else {
+ string err = "[foundations][initial cards] is invalid: " + ic_str;
+ json_helper::json_parse_err(err);
+ }
} else {
- json_helper::json_parse_err("[foundations][initial card] must be a boolean");
+ json_helper::json_parse_err("[foundations][initial cards] must be a string");
+ }
+ }
+
+ if (d["foundations"].HasMember("base card")) {
+ if (d["foundations"]["base card"].IsString()) {
+ string base_card_str = d["foundations"]["base card"].GetString();
+
+ if (base_card_str == "random") {
+ sr.foundations_base = boost::none;
+ } else {
+ base_card_str += "H";
+ sr.foundations_base = card(base_card_str.c_str()).get_rank();
+ }
+ } else {
+ json_helper::json_parse_err("[foundations][base card] must be a string");
}
}
@@ -446,7 +496,6 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
"must be true");
}
- rules_schema_json(); // Throws an error if it fails
Document vd;
vd.Parse(rules_schema_json().c_str());
assert(!vd.HasParseError());
@@ -485,15 +534,24 @@ string rules_parser::rules_schema_json() {
"enum": [
"any",
"no-build",
- "kings"
+ "kings",
+ "auto-reserve-then-waste"
]
},
"diagonal deal": {
"type": "boolean"
},
- "move built group": {
+ "wraps": {
"type": "boolean"
},
+ "move built group": {
+ "type": "string",
+ "enum": [
+ "yes",
+ "no",
+ "whole-pile"
+ ]
+ },
"move built group policy": {
"type": "string",
"enum": [
@@ -520,8 +578,20 @@ string rules_parser::rules_schema_json() {
"present": {
"type": "boolean"
},
- "initial card": {
- "type": "boolean"
+ "initial cards": {
+ "type": "string",
+ "enum": [
+ "none",
+ "one",
+ "all"
+ ]
+ },
+ "base card": {
+ "type": "string",
+ "oneOf":[
+ {"pattern": "^(([0-9]|1[0-3]|a|A|j|J|q|Q|k|K))$"},
+ {"enum": ["random"]}
+ ]
},
"removable": {
"type": "boolean"
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index 0c96651..0aee219 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -25,13 +25,15 @@ map<string, string> sol_preset_types::mp = {
"build policy": "any-suit",
"spaces policy": "any",
"diagonal deal": false,
- "move built group": false,
+ "wraps": false,
+ "move built group": "no",
"move built group policy": "same-as-build",
"face up cards": "all"
},
"foundations": {
"present": true,
- "initial card": false,
+ "initial cards": "none",
+ "base card": "A",
"removable": false,
"only complete pile moves": false
},
@@ -200,7 +202,7 @@ map<string, string> sol_preset_types::mp = {
"build policy": "same-suit"
},
"foundations": {
- "initial card": true
+ "initial cards": "all"
},
"stock": {
"size": 36
@@ -219,7 +221,7 @@ map<string, string> sol_preset_types::mp = {
"build policy": "same-suit"
},
"foundations": {
- "initial card": true
+ "initial cards": "all"
},
"stock": {
"size": 3
@@ -274,13 +276,21 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 4,
"build policy": "red-black",
- "move built group": true
+ "move built group": "whole-pile",
+ "spaces policy": "auto-reserve-then-waste",
+ "wraps": true
+ },
+ "foundations": {
+ "initial cards": "one",
+ "base card": "random"
},
"stock": {
- "size": 34
+ "size": 34,
+ "deal count": 3,
+ "redeal": true
},
"reserve": {
- "size": 14,
+ "size": 13,
"stacked": true
}
}
@@ -295,10 +305,18 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 3,
"build policy": "red-black",
- "move built group": true
+ "move built group": "whole-pile",
+ "spaces policy": "auto-reserve-then-waste",
+ "wraps": true
+ },
+ "foundations": {
+ "initial cards": "one",
+ "base card": "random"
},
"stock": {
- "size": 1
+ "size": 6,
+ "deal count": 3,
+ "redeal": true
},
"reserve": {
"size": 2,
@@ -352,10 +370,10 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 12,
"build policy": "same-suit",
- "move built group": true
+ "move built group": "yes"
},
"foundations": {
- "initial card": true
+ "initial cards": "all"
}
}
)"
@@ -369,10 +387,10 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 3,
"build policy": "same-suit",
- "move built group": true
+ "move built group": "yes"
},
"foundations": {
- "initial card": true
+ "initial cards": "all"
},
"max rank": 6
}
@@ -387,7 +405,7 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 10,
"build policy": "any-suit",
- "move built group": true,
+ "move built group": "yes",
"move built group policy": "same-suit"
},
"foundations": {
@@ -410,7 +428,7 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 4,
"build policy": "any-suit",
- "move built group": true,
+ "move built group": "yes",
"move built group policy": "same-suit"
},
"foundations": {
@@ -435,7 +453,7 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 4,
"build policy": "red-black",
- "move built group": true,
+ "move built group": "yes",
"diagonal deal": true,
"face up cards": "top"
},
@@ -465,7 +483,7 @@ map<string, string> sol_preset_types::mp = {
},
"foundations": {
"removable": true,
- "initial card": true
+ "initial cards": "all"
}
}
)"
@@ -481,7 +499,7 @@ map<string, string> sol_preset_types::mp = {
"count": 7,
"build policy": "red-black",
"spaces policy": "kings",
- "move built group": true,
+ "move built group": "yes",
"diagonal deal": true,
"face up cards": "top"
},
@@ -507,7 +525,7 @@ map<string, string> sol_preset_types::mp = {
"count": 7,
"build policy": "red-black",
"spaces policy": "kings",
- "move built group": true,
+ "move built group": "yes",
"diagonal deal": true,
"face up cards": "top"
},
@@ -567,7 +585,7 @@ map<string, string> sol_preset_types::mp = {
"build policy": "same-suit"
},
"foundations": {
- "initial card": true
+ "initial cards": "all"
}
}
)"
@@ -583,7 +601,7 @@ map<string, string> sol_preset_types::mp = {
"build policy": "red-black"
},
"foundations": {
- "initial card": true,
+ "initial cards": "all",
"removable": true
}
}
@@ -600,7 +618,7 @@ map<string, string> sol_preset_types::mp = {
"build policy": "red-black"
},
"foundations": {
- "initial card": true,
+ "initial cards": "all",
"removable": true
},
"cells": 1
@@ -618,7 +636,7 @@ map<string, string> sol_preset_types::mp = {
"build policy": "red-black"
},
"foundations": {
- "initial card": true,
+ "initial cards": "all",
"removable": true
},
"cells": 2
@@ -796,12 +814,12 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 7,
"build policy": "same-suit",
- "move built group": true,
+ "move built group": "yes",
"spaces policy": "kings"
},
"cells": 7,
"foundations": {
- "initial card": true
+ "initial cards": "all"
}
}
)"
@@ -815,7 +833,7 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 10,
"build policy": "same-suit",
- "move built group": true,
+ "move built group": "yes",
"spaces policy": "kings"
},
"cells": 4
@@ -831,10 +849,10 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 4,
"build policy": "red-black",
- "move built group": true
+ "move built group": "yes"
},
"foundations": {
- "initial card": true
+ "initial cards": "all"
},
"reserve": {
"size": 12
@@ -854,7 +872,7 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 3,
"build policy": "any-suit",
- "move built group": true
+ "move built group": "yes"
},
"reserve": {
"size": 13,
@@ -909,10 +927,10 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 6,
"build policy": "red-black",
- "move built group": true
+ "move built group": "yes"
},
"foundations": {
- "initial card": true,
+ "initial cards": "all",
"removable": true
},
"stock": {
@@ -930,7 +948,7 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 7,
"build policy": "red-black",
- "move built group": true,
+ "move built group": "yes",
"face up cards": "top"
},
"foundations": {
@@ -951,7 +969,7 @@ map<string, string> sol_preset_types::mp = {
{
"tableau piles": {
"build policy": "red-black",
- "move built group": true,
+ "move built group": "yes",
"spaces policy": "kings",
"diagonal deal": true
},
@@ -993,7 +1011,7 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 7,
"build policy": "any-suit",
- "move built group": true,
+ "move built group": "yes",
"move built group policy": "same-suit",
"diagonal deal": true
},
@@ -1016,7 +1034,7 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 7,
"build policy": "any-suit",
- "move built group": true,
+ "move built group": "yes",
"move built group policy": "same-suit"
},
"foundations": {
@@ -1038,7 +1056,7 @@ map<string, string> sol_preset_types::mp = {
"tableau piles": {
"count": 10,
"diagonal deal": true,
- "move built group": true,
+ "move built group": "yes",
"move built group policy": "same-suit"
},
"foundations": {