aboutsummaryrefslogtreecommitdiff
path: root/src/main/input-output/deal_parser.cpp
diff options
context:
space:
mode:
authorCharlie Blake2018-01-09 08:58:30 +0000
committerGitHub2018-01-09 08:58:30 +0000
commit93bfbeec309b027331f75d10864c99f19a958cfd (patch)
tree5ad08a4621dbc118480553d53666e3e507ce584e /src/main/input-output/deal_parser.cpp
parentMerge pull request #27 from thecharlesblake/efficient-implementation (diff)
parentAdd spider to benchmark script (diff)
downloadmetasol-93bfbeec309b027331f75d10864c99f19a958cfd.tar.gz
metasol-93bfbeec309b027331f75d10864c99f19a958cfd.zip

Merge pull request #28 from thecharlesblake/all-canonical-games

All canonical games

Diffstat (limited to 'src/main/input-output/deal_parser.cpp')
-rw-r--r--src/main/input-output/deal_parser.cpp82
1 files changed, 0 insertions, 82 deletions
diff --git a/src/main/input-output/deal_parser.cpp b/src/main/input-output/deal_parser.cpp
deleted file mode 100644
index c876e91..0000000
--- a/src/main/input-output/deal_parser.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-//
-// Created by thecharlesblake on 10/21/17.
-//
-
-#include "deal_parser.h"
-#include "../game/game_state.h"
-#include "../util/util.h"
-
-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) {
- // Construct tableau piles
- if (gs.rules.tableau_pile_count > 0) {
- parse_tableau_piles(gs, doc);
- }
-
- // Construct hole card
- if (gs.rules.hole) {
- parse_hole(gs, doc);
- }
-
- // Construct filled cells
- if (gs.rules.cells) {
- parse_cells(gs, doc);
- }
-}
-
-void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document& doc) {
- assert(doc.HasMember("tableau piles"));
- const Value& json_tab_piles = doc["tableau piles"];
- assert(json_tab_piles.IsArray());
-
- if (gs.tableau_piles.size() != gs.rules.tableau_pile_count) {
- util::json_parse_err("Incorrect number of tableau piles");
- }
-
- for (auto p = std::make_pair(begin(json_tab_piles.GetArray()), begin(gs.tableau_piles));
- p.second != end(gs.tableau_piles);
- ++p.first, ++p.second) {
-
- for (auto& json_card : p.first->GetArray()) {
- assert(json_card.IsString());
- gs.piles[*p.second].place(card(json_card.GetString()));
- }
- }
-}
-
-void deal_parser::parse_hole(game_state &gs, const Document& doc) {
- if (doc.HasMember("hole")) {
- const Value &json_hole = doc["hole"];
- assert(json_hole.IsString());
-
- gs.piles[gs.hole].place(card(json_hole.GetString()));
- }
-}
-
-void deal_parser::parse_cells(game_state &gs, const Document& doc) {
- if (doc.HasMember("cells")) {
- const Value &json_cells = doc["cells"];
- assert(json_cells.IsArray());
-
- const auto json_cell_arr = json_cells.GetArray();
-
- if (json_cell_arr.Empty()) return;
- else if (gs.rules.cells != json_cell_arr.Size()) {
- util::json_parse_err("Incorrect number of cells");
- }
-
- for (auto p = std::make_pair(begin(json_cell_arr), begin(gs.cells));
- p.second != end(gs.cells);
- ++p.first, ++p.second) {
-
- auto json_card = p.first;
- assert(json_card->IsString());
- gs.piles[*p.second].place(json_card->GetString());
- }
- }
-}