From 6a5a840f678aa78659b51ec647dcced4544c4a0b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 28 Oct 2017 15:29:17 +0100 Subject: Modify game state generation to work across sols --- src/main/game_state.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/main/game_state.cpp') diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp index 28f6d3b..9d0349d 100644 --- a/src/main/game_state.cpp +++ b/src/main/game_state.cpp @@ -16,15 +16,13 @@ using namespace rapidjson; using namespace std; // Construct an initial game state from a JSON doc -game_state::game_state(const Document& doc, string sol_type) - : max_rank(1) { - max_rank = sol_type == "simple-black-hole" ? 7 : 13; - +game_state::game_state(const Document& doc) { // 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()) { vector tableau_pile; @@ -45,22 +43,27 @@ game_state::game_state(const Document& doc, string sol_type) } // Construct an initial game state from a seed -game_state::game_state(int seed, string sol_type) { - max_rank = sol_type == "simple-black-hole" ? 7 : 13; - - vector deck = shuffled_deck(seed, max_rank); +game_state::game_state(int seed, const sol_rules& rules) { + vector deck = shuffled_deck(seed, rules.max_rank); + // Deal to the tableau piles (row-by-row) for (vector::size_type i = 0; i < deck.size(); i++) { - // Don't add the Ace of Spades to the hole card card c = deck[i]; - if (c == "AS") continue; + + // If there is a hole card, don't deal the ace of spades + if (rules.hole && c == "AS") { + hole_card = "AS"; + continue; + } + + // For the first row we must create all the tableau pile vectors + if (i / rules.tableau_pile_count == 0) { + tableau_piles.push_back(vector()); + } // Add the randomly generated card to the tableau piles - if (i % 3 == 0) tableau_piles.push_back(vector()); - tableau_piles[i / 3].push_back(deck[i]); + tableau_piles[i % rules.tableau_pile_count].push_back(c); } - - hole_card = "AS"; } // Generate a randomly ordered vector of cards -- cgit v1.2.1