From bf23d041cb9e7d5f1dcad6b26a93c43a69fce8bc Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 26 Dec 2017 13:00:48 +0000 Subject: Refactor game state to prep for deal parse --- src/main/game/game_state.cpp | 41 ++++++----------------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) (limited to 'src/main/game/game_state.cpp') diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 2b77fec..580e454 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -21,44 +21,15 @@ typedef sol_rules::build_order ord; typedef sol_rules::build_policy pol; // Construct an initial game state from a JSON doc -game_state::game_state(const Document& doc) - : reserve(true, ord::NO_BUILD, pol::ANY_SUIT, false), - stock(true, ord::NO_BUILD, pol::ANY_SUIT, false), - waste(true, ord::NO_BUILD, pol::ANY_SUIT, false), - hole(false, ord::BOTH, pol::ANY_SUIT, true, rules.max_rank), - rules(sol_rules::from_preset("simple-black-hole")) { - // Construct tableau piles - assert(doc.HasMember("tableau piles")); - const Value& json_tab_piles = doc["tableau piles"]; - assert(json_tab_piles.IsArray()); - - int max_rank = 1; - for (auto& json_tab : json_tab_piles.GetArray()) { - pile tableau_pile(true, rules.build_ord, pol::ANY_SUIT, false); - - for (auto& json_card : json_tab.GetArray()) { - card c(json_card.GetString()); - if (c.get_rank() > max_rank) max_rank = c.get_rank(); - tableau_pile.place(c); - } - - tableau_piles.push_back(tableau_pile); - } - - // Assign hole card - assert(doc.HasMember("hole card")); - const Value& json_h_card = doc["hole card"]; - assert(json_h_card.IsString()); - hole.place(json_h_card.GetString()); -} - -// Construct an initial game state from a seed -game_state::game_state(int seed, const sol_rules& s_rules) : +game_state::game_state(const sol_rules& s_rules) : + rules(s_rules), reserve(pile::reserve_factory()), stock(pile::stock_factory()), waste(pile::waste_factory()), - hole(pile::hole_factory(s_rules.max_rank)), - rules(s_rules) { + hole(pile::hole_factory(s_rules.max_rank)) {} + +// Construct an initial game state from a seed +game_state::game_state(const sol_rules& s_rules, int seed) : game_state(s_rules) { vector deck = shuffled_deck(seed, rules.max_rank); -- cgit v1.2.1 From b8f4cae869eace06df73ac7c1c390cc42cfe499b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 26 Dec 2017 17:29:24 +0000 Subject: Add basic tableau deal parsing --- src/main/game/game_state.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/main/game/game_state.cpp') diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 580e454..01a17fb 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -12,6 +12,7 @@ #include #include "game_state.h" +#include "../input-output/deal_parser.h" using namespace std; using namespace rapidjson; @@ -26,10 +27,18 @@ game_state::game_state(const sol_rules& s_rules) : reserve(pile::reserve_factory()), stock(pile::stock_factory()), waste(pile::waste_factory()), - hole(pile::hole_factory(s_rules.max_rank)) {} + hole(pile::hole_factory(s_rules.max_rank)) { +} + +// Construct an initial game state from a JSON doc +game_state::game_state(const sol_rules& s_rules, const Document& doc) : + game_state(s_rules) { + deal_parser::parse(*this, doc); +} // Construct an initial game state from a seed -game_state::game_state(const sol_rules& s_rules, int seed) : game_state(s_rules) { +game_state::game_state(const sol_rules& s_rules, int seed) : + game_state(s_rules) { vector deck = shuffled_deck(seed, rules.max_rank); @@ -328,4 +337,3 @@ size_t hash_value(game_state const& gs) { size_t hash_value(vector const& vp) { return hash_range(begin(vp), end(vp)); } - -- cgit v1.2.1 From f8931f348ef456d9fac78b5cadad280f81dfcfc6 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 27 Dec 2017 00:04:32 +0000 Subject: First sp test working --- src/main/game/game_state.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/main/game/game_state.cpp') diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 01a17fb..b851f2a 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -28,6 +28,25 @@ game_state::game_state(const sol_rules& s_rules) : stock(pile::stock_factory()), waste(pile::waste_factory()), hole(pile::hole_factory(s_rules.max_rank)) { + + // Creates the tableau piles + for (unsigned int i = 0; i < rules.tableau_pile_count; i++) { + tableau_piles.push_back(pile::tableau_factory(rules.build_ord)); + } + + // If there are foundation piles, create the relevant pile vectors + if (rules.foundations) { + for (int i = 0; i < 4; i++) { + foundations.push_back(pile::foundation_factory(pol(i))); + } + } + + // If there are cell piles, create the relevant cell vectors + if (rules.cells > 0) { + for (unsigned int i = 0; i < rules.cells; i++) { + cells.push_back(pile::cell_factory()); + } + } } // Construct an initial game state from a JSON doc @@ -64,11 +83,6 @@ game_state::game_state(const sol_rules& s_rules, int seed) : } } - // Creates the tableau piles - for (unsigned int i = 0; i < rules.tableau_pile_count; i++) { - tableau_piles.push_back(pile::tableau_factory(rules.build_ord)); - } - // Deal to the tableau piles (row-by-row) unsigned int t = 0; while (!deck.empty()) { @@ -78,20 +92,6 @@ game_state::game_state(const sol_rules& s_rules, int seed) : // Add the randomly generated card to the tableau piles tableau_piles[t++ % rules.tableau_pile_count].place(c); } - - // If there are foundation piles, create the relevant pile vectors - if (rules.foundations) { - for (int i = 0; i < 4; i++) { - foundations.push_back(pile::foundation_factory(pol(i))); - } - } - - // If there are cell piles, create the relevant cell vectors - if (rules.cells > 0) { - for (unsigned int i = 0; i < rules.cells; i++) { - cells.push_back(pile::cell_factory()); - } - } } // Generate a randomly ordered vector of cards -- cgit v1.2.1