diff options
| author | thecharlesblake | 2017-11-12 10:51:09 +0000 |
|---|---|---|
| committer | thecharlesblake | 2017-11-12 10:51:09 +0000 |
| commit | c651b6894081ba71609249c98f61789ebbe31f0d (patch) | |
| tree | c7f01462ec7178346d62f3d4da489f00c74f04ca /src | |
| parent | Clean up sol_rules class (diff) | |
| download | metasol-c651b6894081ba71609249c98f61789ebbe31f0d.tar.gz metasol-c651b6894081ba71609249c98f61789ebbe31f0d.zip | |
Add factory to pile class to create std pile types
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/game/game_state.cpp | 18 | ||||
| -rw-r--r-- | src/main/game/game_state.h | 4 | ||||
| -rw-r--r-- | src/main/game/pile.cpp | 38 | ||||
| -rw-r--r-- | src/main/game/pile.h | 11 |
4 files changed, 53 insertions, 18 deletions
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 9432239..9d03155 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -12,7 +12,6 @@ #include <rapidjson/document.h> #include "game_state.h" -#include "pile.h" using namespace rapidjson; using namespace std; @@ -54,10 +53,10 @@ game_state::game_state(const Document& doc) // Construct an initial game state from a seed game_state::game_state(int seed, const sol_rules& s_rules) : - 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, s_rules.max_rank), + reserve(pile::reserve_factory()), + stock(pile::stock_factory()), + waste(pile::waste_factory()), + hole(pile::hole_factory(s_rules.max_rank)), rules(s_rules) { vector<card> deck = shuffled_deck(seed, rules.max_rank); @@ -94,8 +93,7 @@ game_state::game_state(int seed, const sol_rules& s_rules) : // For the first row we must create all the tableau pile vectors if (i / rules.tableau_pile_count == 0) { - pile p(true, rules.build_ord, pol::ANY_SUIT, false); - tableau_piles.push_back(p); + tableau_piles.push_back(pile::tableau_factory(rules.build_ord)); } // Add the randomly generated card to the tableau piles @@ -107,16 +105,14 @@ game_state::game_state(int seed, const sol_rules& s_rules) : // If there are foundation piles, create the relevant pile vectors if (rules.foundations) { for (int i = 0; i < 4; i++) { - pile p(true, ord::ASCENDING, pol(i), false); - foundations.push_back(p); + 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++) { - pile p(true, ord::SINGLE_CARD, pol::ANY_SUIT, false); - cells.push_back(p); + cells.push_back(pile::cell_factory()); } } } diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index e856056..b985924 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -41,9 +41,9 @@ private: void print_hole(std::ostream&) const; void print_pile(std::ostream&, const pile&) const; - std::vector<pile> tableau_piles; - std::vector<pile> cells; std::vector<pile> foundations; + std::vector<pile> cells; + std::vector<pile> tableau_piles; pile reserve; pile stock; pile waste; diff --git a/src/main/game/pile.cpp b/src/main/game/pile.cpp index 776c997..84a6046 100644 --- a/src/main/game/pile.cpp +++ b/src/main/game/pile.cpp @@ -9,8 +9,40 @@ using namespace std; -pile::pile(bool r, sol_rules::build_order bo, sol_rules::build_policy bp, - bool l, int mr) : +typedef sol_rules::build_order ord; +typedef sol_rules::build_policy pol; + +//////////// +// Static // +//////////// + +pile pile::foundation_factory(pol p) { + return pile(true, ord::ASCENDING, p, false); +} +pile pile::cell_factory() { + return pile(true, ord::SINGLE_CARD, pol::ANY_SUIT, false); +} +pile pile::tableau_factory(ord o) { + return pile(true, o, pol::ANY_SUIT, false); +} +pile pile::reserve_factory() { + return pile(true, ord::NO_BUILD, pol::ANY_SUIT, false); +} +pile pile::stock_factory() { + return pile(true, ord::NO_BUILD, pol::ANY_SUIT, false); +} +pile pile::waste_factory() { + return pile(true, ord::NO_BUILD, pol::ANY_SUIT, false); +} +pile pile::hole_factory(int max_rank) { + return pile(false, ord::BOTH, pol::ANY_SUIT, true, max_rank); +} + +//////////////// +// Non-static // +//////////////// + +pile::pile(bool r, ord bo, pol bp, bool l, int mr) : remove(r), build_order(bo), build_policy(bp), @@ -18,8 +50,6 @@ pile::pile(bool r, sol_rules::build_order bo, sol_rules::build_policy bp, max_rank(mr) {} bool pile::can_place(const card& c) const { - typedef sol_rules::build_order ord; - typedef sol_rules::build_policy pol; if (build_order == ord::NO_BUILD) { return false; diff --git a/src/main/game/pile.h b/src/main/game/pile.h index c967cc1..807364f 100644 --- a/src/main/game/pile.h +++ b/src/main/game/pile.h @@ -12,7 +12,16 @@ class pile { public: - pile(bool, sol_rules::build_order, sol_rules::build_policy, bool, int m = 13); + static pile foundation_factory(sol_rules::build_policy); + static pile cell_factory(); + static pile tableau_factory(sol_rules::build_order); + static pile reserve_factory(); + static pile stock_factory(); + static pile waste_factory(); + static pile hole_factory(int max_rank = 13); + + pile(bool, sol_rules::build_order, sol_rules::build_policy, bool, + int max_rank = 13); bool can_place(const card&) const; bool can_remove() const; |
