aboutsummaryrefslogtreecommitdiff
path: root/src/main/input-output/input/json-parsing/deal_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/input-output/input/json-parsing/deal_parser.cpp')
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.cpp31
1 files changed, 14 insertions, 17 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 6f0694d..b2a4c9d 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.cpp
+++ b/src/main/input-output/input/json-parsing/deal_parser.cpp
@@ -9,7 +9,6 @@
using namespace std;
using namespace rapidjson;
-typedef sol_rules::build_order ord;
typedef sol_rules::build_policy pol;
void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) {
@@ -49,7 +48,7 @@ void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document&
const Value& json_tab_piles = doc["tableau piles"];
assert(json_tab_piles.IsArray());
- if (gs.tableau_piles.size() != gs.rules.tableau_pile_count) {
+ if (json_tab_piles.Size() != gs.rules.tableau_pile_count ) {
json_helper::json_parse_err("Incorrect number of tableau piles");
}
@@ -57,6 +56,7 @@ void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document&
p.second != end(gs.tableau_piles);
++p.first, ++p.second) {
+ assert(p.first->IsArray());
for (auto& json_card : p.first->GetArray()) {
assert(json_card.IsString());
gs.piles[*p.second].place(card(json_card.GetString()));
@@ -81,7 +81,7 @@ void deal_parser::parse_cells(game_state &gs, const Document& doc) {
const auto json_cell_arr = json_cells.GetArray();
if (json_cell_arr.Empty()) return;
- else if (gs.rules.cells != json_cell_arr.Size()) {
+ else if (json_cell_arr.Size() != gs.rules.cells) {
json_helper::json_parse_err("Incorrect number of cells");
}
@@ -101,11 +101,12 @@ void deal_parser::parse_stock(game_state &gs, const Document& doc) {
const Value &json_stock = doc["stock"];
assert(json_stock.IsArray());
- if (gs.rules.stock_size != json_stock.Size()) {
+ if (json_stock.Size() != gs.rules.stock_size) {
json_helper::json_parse_err("Incorrect stock size");
}
for (const Value& json_card : json_stock.GetArray()) {
+ assert(json_card.IsString());
gs.piles[gs.stock].place(card(json_card.GetString()));
}
}
@@ -116,21 +117,14 @@ void deal_parser::parse_reserve(game_state &gs, const Document& doc) {
const Value& json_reserve_piles = doc["reserve"];
assert(json_reserve_piles.IsArray());
+ const auto& json_card_arr = json_reserve_piles.GetArray();
+
// 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");
- }
+ if (json_reserve_piles.Size() != gs.rules.reserve_size) {
+ json_helper::json_parse_err("Incorrect reserve size");
}
- 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];
@@ -140,9 +134,12 @@ void deal_parser::parse_reserve(game_state &gs, const Document& doc) {
}
void deal_parser::fill_foundations(game_state &gs) {
- for (uint8_t f_idx = 0; f_idx < 4; f_idx++) {
+ auto foundations_count = uint8_t(4 * (gs.rules.two_decks ? 2:1));
+ assert(gs.foundations.size() == foundations_count);
+
+ for (uint8_t f_idx = 0; f_idx < foundations_count; f_idx++) {
gs.piles[gs.foundations[f_idx]].place(
- card(card::to_suit(f_idx), 1)
+ card(card::to_suit(f_idx % uint8_t(4)), 1)
);
}
}