aboutsummaryrefslogtreecommitdiff
path: root/src/main/input-output/input
diff options
context:
space:
mode:
authorthecharlesblake2018-01-18 13:47:38 +0000
committerthecharlesblake2018-01-18 13:47:38 +0000
commit0111172d25f73a23e9390025f71620d60f2f6c86 (patch)
tree1fdcf7a33592f6b03b497b477be030fee8a91422 /src/main/input-output/input
parentUpdate card printing to use to string method (diff)
downloadmetasol-0111172d25f73a23e9390025f71620d60f2f6c86.tar.gz
metasol-0111172d25f73a23e9390025f71620d60f2f6c86.zip

Update parsing to check correct features

Diffstat (limited to 'src/main/input-output/input')
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.cpp26
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.h2
-rw-r--r--src/main/input-output/input/json-parsing/rules_parser.cpp1
3 files changed, 14 insertions, 15 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 b2a4c9d..7cf5f45 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.cpp
+++ b/src/main/input-output/input/json-parsing/deal_parser.cpp
@@ -13,32 +13,32 @@ typedef sol_rules::build_policy pol;
void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) {
// Construct tableau piles
- if (gs.rules.tableau_pile_count > 0) {
+ if (game_state::rules.tableau_pile_count > 0) {
parse_tableau_piles(gs, doc);
}
// Construct hole card
- if (gs.rules.hole) {
+ if (game_state::rules.hole) {
parse_hole(gs, doc);
}
// Construct filled cells
- if (gs.rules.cells) {
+ if (game_state::rules.cells) {
parse_cells(gs, doc);
}
// Construct stock
- if (gs.rules.stock_size > 0) {
+ if (game_state::rules.stock_size > 0) {
parse_stock(gs, doc);
}
// Construct reserve
- if (gs.rules.reserve_size > 0) {
+ if (game_state::rules.reserve_size > 0) {
parse_reserve(gs, doc);
}
// If the foundations begin with cards in them, fill them
- if (gs.rules.foundations_init_card) {
+ if (game_state::rules.foundations_init_card) {
fill_foundations(gs);
}
}
@@ -48,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 (json_tab_piles.Size() != gs.rules.tableau_pile_count ) {
+ if (json_tab_piles.Size() != game_state::rules.tableau_pile_count ) {
json_helper::json_parse_err("Incorrect number of tableau piles");
}
@@ -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 (json_cell_arr.Size() != gs.rules.cells) {
+ else if (json_cell_arr.Size() != game_state::rules.cells) {
json_helper::json_parse_err("Incorrect number of cells");
}
@@ -101,7 +101,7 @@ void deal_parser::parse_stock(game_state &gs, const Document& doc) {
const Value &json_stock = doc["stock"];
assert(json_stock.IsArray());
- if (json_stock.Size() != gs.rules.stock_size) {
+ if (json_stock.Size() != game_state::rules.stock_size) {
json_helper::json_parse_err("Incorrect stock size");
}
@@ -121,25 +121,25 @@ 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) {
+ if (json_reserve_piles.Size() != game_state::rules.reserve_size) {
json_helper::json_parse_err("Incorrect reserve size");
}
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;
+ if (!game_state::rules.reserve_stacked) pr += i;
gs.piles[pr].place(card(json_card_arr[i].GetString()));
}
}
void deal_parser::fill_foundations(game_state &gs) {
- auto foundations_count = uint8_t(4 * (gs.rules.two_decks ? 2:1));
+ auto foundations_count = uint8_t(4 * (game_state::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 % uint8_t(4)), 1)
+ card(f_idx % uint8_t(4), 1)
);
}
}
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 ecb596c..98916cd 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.h
+++ b/src/main/input-output/input/json-parsing/deal_parser.h
@@ -11,8 +11,6 @@
#include <rapidjson/document.h>
#include <rapidjson/schema.h>
-#include "../../../game/sol_rules.h"
-
class game_state;
class deal_parser {
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 9154ffd..7b9de84 100644
--- a/src/main/input-output/input/json-parsing/rules_parser.cpp
+++ b/src/main/input-output/input/json-parsing/rules_parser.cpp
@@ -8,6 +8,7 @@
#include "rules_parser.h"
#include "json_helper.h"
#include "../sol_preset_types.h"
+#include "../../../game/card.h"
using namespace std;
using namespace rapidjson;