aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorCharlie Blake2018-07-11 11:56:37 +0100
committerCharlie Blake2018-07-11 11:56:37 +0100
commit5f67ae3c634cdeebda84189f41734c9f4a4657b3 (patch)
tree251d0edc1ab11a42c2da47d6f0c3754414531b6c /src/main
parentAdd logic to take cards from within piles (diff)
downloadmetasol-5f67ae3c634cdeebda84189f41734c9f4a4657b3.tar.gz
metasol-5f67ae3c634cdeebda84189f41734c9f4a4657b3.zip

Parse sequence from deal

Diffstat (limited to 'src/main')
-rw-r--r--src/main/game/search-state/game_state.cpp6
-rw-r--r--src/main/game/search-state/game_state.h1
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.cpp27
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.h1
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp2
5 files changed, 36 insertions, 1 deletions
diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp
index 0720f6e..1af554c 100644
--- a/src/main/game/search-state/game_state.cpp
+++ b/src/main/game/search-state/game_state.cpp
@@ -104,6 +104,12 @@ game_state::game_state(const sol_rules& s_rules, streamliner_options stream_opts
tableau_piles.push_back(static_cast<pile::ref>(piles.size() - 1));
original_tableau_piles.push_back(static_cast<pile::ref>(piles.size() - 1));
}
+
+ // Creates the sequence piles
+ for (uint8_t i = 0; i < rules.sequence_count; i++) {
+ piles.emplace_back();
+ sequences.push_back(static_cast<pile::ref>(piles.size() - 1));
+ }
}
// Constructs an initial game state from a JSON doc
diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h
index 3f354d1..15d237a 100644
--- a/src/main/game/search-state/game_state.h
+++ b/src/main/game/search-state/game_state.h
@@ -136,6 +136,7 @@ private:
pile::ref waste;
std::list<pile::ref> reserve;
std::vector<pile::ref> foundations;
+ std::vector<pile::ref> sequences;
pile::ref hole;
/* Pile references of starting/original layout */
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 7ab2cd2..1b03ef1 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.cpp
+++ b/src/main/input-output/input/json-parsing/deal_parser.cpp
@@ -51,6 +51,11 @@ void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) {
parse_reserve(gs, doc);
}
+ // Construct sequences
+ if (gs.rules.sequence_count > 0) {
+ parse_sequences(gs, doc);
+ }
+
// If the foundations begin with cards in them, fill them
if (gs.rules.foundations_present) {
bool supplied_foundations = parse_foundations(gs, doc);
@@ -209,6 +214,28 @@ void deal_parser::parse_reserve(game_state &gs, const Document& doc) {
}
}
+void deal_parser::parse_sequences(game_state& gs, const rapidjson::Document& doc) {
+ assert(doc.HasMember("sequences"));
+ const Value& json_seqs = doc["sequences"];
+ assert(json_seqs.IsArray());
+
+ if (json_seqs.Size() != gs.rules.sequence_count ) {
+ json_helper::json_parse_err("Incorrect number of sequences");
+ }
+
+ for (auto p = std::make_pair(begin(json_seqs.GetArray()), begin(gs.sequences));
+ p.second != end(gs.sequences);
+ ++p.first, ++p.second) {
+
+ for (auto& json_card : p.first->GetArray()) {
+ assert(json_card.IsString());
+ string card_str = json_card.GetString();
+ card c = card_str.empty() ? card() : card(json_card.GetString());
+ gs.place_card(*p.second, c);
+ }
+ }
+}
+
bool deal_parser::parse_foundations(game_state &gs, const rapidjson::Document& doc) {
if (!doc.HasMember("foundations")) return false;
diff --git a/src/main/input-output/input/json-parsing/deal_parser.h b/src/main/input-output/input/json-parsing/deal_parser.h
index c34a93f..bce4a29 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.h
+++ b/src/main/input-output/input/json-parsing/deal_parser.h
@@ -23,6 +23,7 @@ public:
static void parse_stock(game_state&, const rapidjson::Document&);
static void parse_waste(game_state&, const rapidjson::Document&);
static void parse_reserve(game_state&, const rapidjson::Document&);
+ static void parse_sequences(game_state&, const rapidjson::Document&);
static bool parse_foundations(game_state&, const rapidjson::Document&);
static void fill_foundations(game_state&);
static std::string deal_schema_json();
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index a004136..f3606e9 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -1075,7 +1075,7 @@ map<string, string> sol_preset_types::mp = {
"count": 0
},
"sequences": {
- "count": 4,
+ "count": 3,
"direction": "L",
"build policy": "same-suit"
}