From 28c5a79425fa12f9466e27385404f429f76f7524 Mon Sep 17 00:00:00 2001 From: Charlie Blake Date: Thu, 19 Jul 2018 11:06:38 +0100 Subject: Update rules so new schema works w/ existing games --- .../input/json-parsing/deal_parser.cpp | 3 +- .../input/json-parsing/rules_parser.cpp | 37 ++++++++++--- src/main/input-output/input/sol_preset_types.cpp | 62 +++++++++++----------- 3 files changed, 63 insertions(+), 39 deletions(-) (limited to 'src/main/input-output') 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 7b8cf18..7531cec 100644 --- a/src/main/input-output/input/json-parsing/deal_parser.cpp +++ b/src/main/input-output/input/json-parsing/deal_parser.cpp @@ -13,6 +13,7 @@ using namespace rapidjson; typedef sol_rules::build_policy pol; typedef sol_rules::stock_deal_type sdt; typedef sol_rules::face_up_policy fu; +typedef sol_rules::foundations_init_type fit; void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) { // There are two stages to reading in the supplied deal. It is both put @@ -65,7 +66,7 @@ void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) { if (gs.rules.foundations_present) { bool supplied_foundations = parse_foundations(gs, doc); - if (!supplied_foundations && gs.rules.foundations_init_card) { + if (!supplied_foundations && gs.rules.foundations_init_cards == fit::ALL) { fill_foundations(gs); } } 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 f7de6d8..4e0634f 100644 --- a/src/main/input-output/input/json-parsing/rules_parser.cpp +++ b/src/main/input-output/input/json-parsing/rules_parser.cpp @@ -24,6 +24,8 @@ typedef sol_rules::accordion_policy acc_pol; typedef sol_rules::stock_deal_type sdt; typedef sol_rules::face_up_policy fu; typedef sol_rules::direction dir; +typedef sol_rules::built_group_type bgt; +typedef sol_rules::foundations_init_type fit; const sol_rules rules_parser::from_file(const string rules_file) { sol_rules sr = get_default(); @@ -125,10 +127,20 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { } if (d["tableau piles"].HasMember("move built group")) { - if (d["tableau piles"]["move built group"].IsBool()) { - sr.move_built_group = d["tableau piles"]["move built group"].GetBool(); + if (d["tableau piles"]["move built group"].IsString()) { + string mbg_str = d["tableau piles"]["move built group"].GetString(); + + if (mbg_str == "yes") { + sr.move_built_group = bgt::YES; + } else if (mbg_str == "no") { + sr.move_built_group = bgt::NO; + } else if (mbg_str == "whole-pile") { + sr.move_built_group = bgt::WHOLE_PILE; + } else { + json_helper::json_parse_err("[tableau piles][move built group] is invalid"); + } } else { - json_helper::json_parse_err("[tableau piles][move built group] must be a boolean"); + json_helper::json_parse_err("[tableau piles][move built group] must be a string"); } } @@ -198,11 +210,22 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) { } } - if (d["foundations"].HasMember("initial card")) { - if (d["foundations"]["initial card"].IsBool()) { - sr.foundations_init_card = d["foundations"]["initial card"].GetBool(); + if (d["foundations"].HasMember("initial cards")) { + if (d["foundations"]["initial cards"].IsString()) { + string ic_str = d["foundations"]["initial cards"].GetString(); + + if (ic_str == "none") { + sr.foundations_init_cards = fit::NONE; + } else if (ic_str == "one") { + sr.foundations_init_cards = fit::ONE; + } else if (ic_str == "all") { + sr.foundations_init_cards = fit::ALL; + } else { + string err = "[foundations][initial cards] is invalid: " + ic_str; + json_helper::json_parse_err(err); + } } else { - json_helper::json_parse_err("[foundations][initial card] must be a boolean"); + json_helper::json_parse_err("[foundations][initial cards] must be a string"); } } diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index 65100e0..85edcd3 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -202,7 +202,7 @@ map sol_preset_types::mp = { "build policy": "same-suit" }, "foundations": { - "initial card": true + "initial cards": "all" }, "stock": { "size": 36 @@ -221,7 +221,7 @@ map sol_preset_types::mp = { "build policy": "same-suit" }, "foundations": { - "initial card": true + "initial cards": "all" }, "stock": { "size": 3 @@ -276,7 +276,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 4, "build policy": "red-black", - "move built group": true + "move built group": "yes" }, "stock": { "size": 34 @@ -297,7 +297,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 3, "build policy": "red-black", - "move built group": true + "move built group": "yes" }, "stock": { "size": 1 @@ -354,10 +354,10 @@ map sol_preset_types::mp = { "tableau piles": { "count": 12, "build policy": "same-suit", - "move built group": true + "move built group": "yes" }, "foundations": { - "initial card": true + "initial cards": "all" } } )" @@ -371,10 +371,10 @@ map sol_preset_types::mp = { "tableau piles": { "count": 3, "build policy": "same-suit", - "move built group": true + "move built group": "yes" }, "foundations": { - "initial card": true + "initial cards": "all" }, "max rank": 6 } @@ -389,7 +389,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 10, "build policy": "any-suit", - "move built group": true, + "move built group": "yes", "move built group policy": "same-suit" }, "foundations": { @@ -412,7 +412,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 4, "build policy": "any-suit", - "move built group": true, + "move built group": "yes", "move built group policy": "same-suit" }, "foundations": { @@ -437,7 +437,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 4, "build policy": "red-black", - "move built group": true, + "move built group": "yes", "diagonal deal": true, "face up cards": "top" }, @@ -467,7 +467,7 @@ map sol_preset_types::mp = { }, "foundations": { "removable": true, - "initial card": true + "initial cards": "all" } } )" @@ -483,7 +483,7 @@ map sol_preset_types::mp = { "count": 7, "build policy": "red-black", "spaces policy": "kings", - "move built group": true, + "move built group": "yes", "diagonal deal": true, "face up cards": "top" }, @@ -509,7 +509,7 @@ map sol_preset_types::mp = { "count": 7, "build policy": "red-black", "spaces policy": "kings", - "move built group": true, + "move built group": "yes", "diagonal deal": true, "face up cards": "top" }, @@ -569,7 +569,7 @@ map sol_preset_types::mp = { "build policy": "same-suit" }, "foundations": { - "initial card": true + "initial cards": "all" } } )" @@ -585,7 +585,7 @@ map sol_preset_types::mp = { "build policy": "red-black" }, "foundations": { - "initial card": true, + "initial cards": "all", "removable": true } } @@ -602,7 +602,7 @@ map sol_preset_types::mp = { "build policy": "red-black" }, "foundations": { - "initial card": true, + "initial cards": "all", "removable": true }, "cells": 1 @@ -620,7 +620,7 @@ map sol_preset_types::mp = { "build policy": "red-black" }, "foundations": { - "initial card": true, + "initial cards": "all", "removable": true }, "cells": 2 @@ -798,12 +798,12 @@ map sol_preset_types::mp = { "tableau piles": { "count": 7, "build policy": "same-suit", - "move built group": true, + "move built group": "yes", "spaces policy": "kings" }, "cells": 7, "foundations": { - "initial card": true + "initial cards": "all" } } )" @@ -817,7 +817,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 10, "build policy": "same-suit", - "move built group": true, + "move built group": "yes", "spaces policy": "kings" }, "cells": 4 @@ -833,10 +833,10 @@ map sol_preset_types::mp = { "tableau piles": { "count": 4, "build policy": "red-black", - "move built group": true + "move built group": "yes" }, "foundations": { - "initial card": true + "initial cards": "all" }, "reserve": { "size": 12 @@ -856,7 +856,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 3, "build policy": "any-suit", - "move built group": true + "move built group": "yes" }, "reserve": { "size": 13, @@ -911,10 +911,10 @@ map sol_preset_types::mp = { "tableau piles": { "count": 6, "build policy": "red-black", - "move built group": true + "move built group": "yes" }, "foundations": { - "initial card": true, + "initial cards": "all", "removable": true }, "stock": { @@ -932,7 +932,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 7, "build policy": "red-black", - "move built group": true, + "move built group": "yes", "face up cards": "top" }, "foundations": { @@ -953,7 +953,7 @@ map sol_preset_types::mp = { { "tableau piles": { "build policy": "red-black", - "move built group": true, + "move built group": "yes", "spaces policy": "kings", "diagonal deal": true }, @@ -995,7 +995,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 7, "build policy": "any-suit", - "move built group": true, + "move built group": "yes", "move built group policy": "same-suit", "diagonal deal": true }, @@ -1018,7 +1018,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 7, "build policy": "any-suit", - "move built group": true, + "move built group": "yes", "move built group policy": "same-suit" }, "foundations": { @@ -1040,7 +1040,7 @@ map sol_preset_types::mp = { "tableau piles": { "count": 10, "diagonal deal": true, - "move built group": true, + "move built group": "yes", "move built group policy": "same-suit" }, "foundations": { -- cgit v1.2.1