From f56486a83a03ab58fd3f455258de4caebe239322 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 2 Jan 2018 11:29:16 +0000 Subject: Add empty pile logic for bakers dozen --- src/main/game/pile.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/main/game/pile.h') diff --git a/src/main/game/pile.h b/src/main/game/pile.h index 978e32e..a064693 100644 --- a/src/main/game/pile.h +++ b/src/main/game/pile.h @@ -13,7 +13,8 @@ class pile { public: // Factory methods - static pile tableau_factory(sol_rules::build_order, sol_rules::build_policy); + static pile tableau_factory(sol_rules::build_order, sol_rules::build_policy, + sol_rules::spaces_policy); static pile cell_factory(); static pile reserve_factory(); static pile stock_factory(); @@ -24,6 +25,7 @@ public: // Constructors pile(sol_rules::build_order bo = sol_rules::build_order::DESCENDING, sol_rules::build_policy bp = sol_rules::build_policy::ANY_SUIT, + sol_rules::spaces_policy sp = sol_rules::spaces_policy::ANY, bool removable = true, bool loops = false, int max_rank = 13); @@ -54,6 +56,7 @@ private: // const pile properties const sol_rules::build_order build_order; const sol_rules::build_policy build_policy; + const sol_rules::spaces_policy spaces_policy; const bool removable; const bool build_order_loops; const int max_rank; -- cgit v1.2.1 From 77a7aeba7854d15b140cc6dc3c69b15ed5f3b936 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Wed, 3 Jan 2018 12:30:14 +0000 Subject: Major refactor, putting pile logic into game_state Much of the logic that was in the pile class was beginning to seem out of place. A lot of the rules have fairly arbitrary interactons *between* piles, which weren't best represented in the pile classes themselves, which were getting unweildy and inefficient. Hence, much of this logic has been moved to the game state class. --- src/main/game/pile.h | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) (limited to 'src/main/game/pile.h') diff --git a/src/main/game/pile.h b/src/main/game/pile.h index a064693..a51e0f4 100644 --- a/src/main/game/pile.h +++ b/src/main/game/pile.h @@ -12,34 +12,13 @@ class pile { public: - // Factory methods - static pile tableau_factory(sol_rules::build_order, sol_rules::build_policy, - sol_rules::spaces_policy); - static pile cell_factory(); - static pile reserve_factory(); - static pile stock_factory(); - static pile waste_factory(); - static pile foundation_factory(sol_rules::build_policy); - static pile hole_factory(int); - - // Constructors - pile(sol_rules::build_order bo = sol_rules::build_order::DESCENDING, - sol_rules::build_policy bp = sol_rules::build_policy::ANY_SUIT, - sol_rules::spaces_policy sp = sol_rules::spaces_policy::ANY, - bool removable = true, - bool loops = false, - int max_rank = 13); - // Inspect - bool can_place(const card) const; - bool can_remove() const; card top_card() const; bool empty() const; uint8_t size() const; - sol_rules::build_order get_build_order() const; // Modify - void place(const card); + void place(card); card take(); void clear(); @@ -49,18 +28,7 @@ public: friend bool operator==(const pile&, const pile&); friend std::size_t hash_value(pile const&); - private: - bool one_lt(int, int) const; - - // const pile properties - const sol_rules::build_order build_order; - const sol_rules::build_policy build_policy; - const sol_rules::spaces_policy spaces_policy; - const bool removable; - const bool build_order_loops; - const int max_rank; - // Underlying vector std::vector pile_vec; }; -- cgit v1.2.1 From 067152f57ced18c5f706144909345125754e8664 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Mon, 8 Jan 2018 19:02:36 +0000 Subject: Add game logic for built pile (AA) and refactor --- src/main/game/pile.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/main/game/pile.h') diff --git a/src/main/game/pile.h b/src/main/game/pile.h index a51e0f4..f2600fe 100644 --- a/src/main/game/pile.h +++ b/src/main/game/pile.h @@ -6,25 +6,27 @@ #define SOLVITAIRE_PILE_H #include +#include #include "sol_rules.h" #include "card.h" class pile { public: + typedef uint8_t size_type; + // Inspect card top_card() const; bool empty() const; - uint8_t size() const; + size_type size() const; // Modify void place(card); card take(); - void clear(); - // Index like array - card& operator[] (std::vector::size_type); - card operator[] (std::vector::size_type) const; + // Indexes the vector, with the top card as index 0 + card& operator[] (size_type); + card operator[] (size_type) const; friend bool operator==(const pile&, const pile&); friend std::size_t hash_value(pile const&); -- cgit v1.2.1