diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/game/game_state.cpp | 41 | ||||
| -rw-r--r-- | src/main/game/game_state.h | 6 | ||||
| -rw-r--r-- | src/main/input-output/deal_parser.cpp | 27 | ||||
| -rw-r--r-- | src/main/main.cpp | 2 |
4 files changed, 36 insertions, 40 deletions
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<card> deck = shuffled_deck(seed, rules.max_rank); diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index 873ca6f..6c0b77b 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -18,9 +18,9 @@ class game_state { public: // Create a game state representation from a JSON doc - game_state(const rapidjson::Document&); + explicit game_state(const sol_rules&); // Do the same from a 'rules' object - game_state(int seed, const sol_rules&); + game_state(const sol_rules&, int seed); const std::vector<game_state> get_next_legal_states() const; bool is_solved() const; @@ -44,6 +44,7 @@ private: void print_top_of_piles(std::ostream&, const std::vector<pile>&) const; void print_top_of_pile(std::ostream&, const pile&) const; + sol_rules rules; std::vector<pile> foundations; std::vector<pile> cells; std::vector<pile> tableau_piles; @@ -51,7 +52,6 @@ private: pile stock; pile waste; pile hole; - sol_rules rules; }; diff --git a/src/main/input-output/deal_parser.cpp b/src/main/input-output/deal_parser.cpp index 9fcd1d1..76da77b 100644 --- a/src/main/input-output/deal_parser.cpp +++ b/src/main/input-output/deal_parser.cpp @@ -21,7 +21,32 @@ deal_parser::deal_parser(const sol_rules &r) : rules(r) {} game_state deal_parser::parse(const string& filename) const { const Document doc = read_file(filename); - game_state gs; + game_state gs(rules); + /* + // 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()); + */ return gs; } diff --git a/src/main/main.cpp b/src/main/main.cpp index ddf8f73..54e9404 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -64,7 +64,7 @@ const optional<sol_rules> gen_rules(command_line_helper& clh) { void solve_random_game(int seed, const sol_rules& rules) { LOG_INFO ("Attempting to solve with seed: " << seed << "..."); - game_state gs(seed, rules); + game_state gs(rules, seed); solve_game(gs, rules); } |
