aboutsummaryrefslogtreecommitdiff
path: root/src/main/input-output/input/json-parsing
diff options
context:
space:
mode:
authorthecharlesblake2018-01-05 15:55:59 +0000
committerthecharlesblake2018-01-05 15:55:59 +0000
commitdc5a834c0d2d2a25f3023f812f8d85376855f0be (patch)
tree5ee1113e85206e4dd8bae6d11c46b4aba27464b3 /src/main/input-output/input/json-parsing
parentAdd rules parsing for stacked reserve (canfield) (diff)
downloadmetasol-dc5a834c0d2d2a25f3023f812f8d85376855f0be.tar.gz
metasol-dc5a834c0d2d2a25f3023f812f8d85376855f0be.zip

Add deal parser for stacked reserve (canfield)

Diffstat (limited to 'src/main/input-output/input/json-parsing')
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.cpp26
1 files changed, 18 insertions, 8 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 8bcb3b6..6f0694d 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.cpp
+++ b/src/main/input-output/input/json-parsing/deal_parser.cpp
@@ -116,16 +116,26 @@ void deal_parser::parse_reserve(game_state &gs, const Document& doc) {
const Value& json_reserve_piles = doc["reserve"];
assert(json_reserve_piles.IsArray());
- if (gs.reserve.size() != gs.rules.reserve_size) {
- json_helper::json_parse_err("Incorrect reserve size");
+ // We treat a regular reserve like multiple single-card piles,
+ // but a stacked reserve as a single multiple-card pile
+ if (gs.rules.reserve_stacked) {
+ if (json_reserve_piles.Size() != gs.rules.reserve_size
+ || json_reserve_piles.Size() != gs.rules.reserve_size) {
+ json_helper::json_parse_err("Incorrect reserve size");
+ }
+ } else {
+ if (gs.reserve.size() != gs.rules.reserve_size
+ || json_reserve_piles.Size() != gs.rules.reserve_size) {
+ json_helper::json_parse_err("Incorrect reserve size");
+ }
}
- for (auto p = std::make_pair(begin(json_reserve_piles.GetArray()), begin(gs.reserve));
- p.second != end(gs.reserve);
- ++p.first, ++p.second) {
-
- assert(p.first->IsString());
- gs.piles[*p.second].place(card(p.first->GetString()));
+ const auto& json_card_arr = json_reserve_piles.GetArray();
+ for (game_state::pile_ref i = 0; i < json_card_arr.Size(); i++) {
+ assert(json_card_arr[i].IsString());
+ game_state::pile_ref pr = gs.reserve[0];
+ if (!gs.rules.reserve_stacked) pr += i;
+ gs.piles[pr].place(card(json_card_arr[i].GetString()));
}
}