From 252c7398925b5267963c1a48251cd7ba2d4ec381 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 25 Jan 2018 15:20:54 +0000 Subject: Refactor game_state & cache to remove static hack --- src/main/game/game_state.h | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/main/game/game_state.h') diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index 8dcffa4..8434bf7 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -18,7 +18,8 @@ class game_state { friend class deal_parser; friend class state_printer; - friend class game_state_pred; + friend class predicate; + friend class hasher; public: // Defines types typedef uint8_t pile_ref; @@ -48,11 +49,7 @@ public: friend std::ostream& operator<< (std::ostream&, const game_state&); - friend std::size_t hash_value(card const&); - friend std::size_t hash_value(game_state const&); - private: - void static_reset(); static std::vector gen_shuffled_deck(int, card::rank_t, bool); // Private constructor @@ -71,14 +68,14 @@ private: card) const; // References to piles - static sol_rules rules; - static std::vector tableau_piles; - static std::vector cells; - static pile_ref stock; - static pile_ref waste; - static std::vector reserve; - static std::vector foundations; - static pile_ref hole; + const sol_rules rules; + std::vector tableau_piles; + std::vector cells; + pile_ref stock; + pile_ref waste; + std::vector reserve; + std::vector foundations; + pile_ref hole; // The core piles std::vector piles; -- cgit v1.2.1 From 9ae4c039b998943dbe771772ee06dfbcad3d6b8a Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Sat, 27 Jan 2018 00:14:42 +0000 Subject: Alter printing to work when pile refs are changed --- src/main/game/game_state.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/main/game/game_state.h') diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index 8434bf7..e8e2f96 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -77,6 +77,12 @@ private: std::vector foundations; pile_ref hole; + // Stores the original pile refs of the commutative piles so that they can + // be printed in the order the user expects + std::vector original_tableau_piles; + std::vector original_cells; + std::vector original_reserve; + // The core piles std::vector piles; }; -- cgit v1.2.1 From 0193418c62d07c7f4134ea65c11fc606cbc0c3f7 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 30 Jan 2018 15:46:16 +0000 Subject: Update game_state so comm piles always ordered --- src/main/game/game_state.h | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/main/game/game_state.h') diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index e8e2f96..fe43d99 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -6,6 +6,7 @@ #define SOLVITAIRE_GAME_STATE_H #include +#include #include #include @@ -20,6 +21,7 @@ class game_state { friend class state_printer; friend class predicate; friend class hasher; + friend class global_cache; public: // Defines types typedef uint8_t pile_ref; @@ -31,15 +33,16 @@ public: // Constructors // Creates a game state representation from a JSON doc game_state(const sol_rules&, const rapidjson::Document&); - // Does the same from a 'rules' object + // Does the same from a seed game_state(const sol_rules&, int seed); - - // For testing - game_state(std::initializer_list); + // Does the same but with an initialiser list (useful for testing) + game_state(const sol_rules&, std::initializer_list); // Alters state void make_move(move); void undo_move(move); + void place_card(pile_ref, card); + card take_card(pile_ref); std::vector get_legal_moves() const; @@ -55,6 +58,10 @@ private: // Private constructor explicit game_state(const sol_rules&); + // Used to maintain pile order invariant + void eval_pile_order(pile_ref, bool); + void eval_pile_order(std::list&, pile_ref, bool); + // Used in get_legal_moves() move get_stock_tableau_move() const; bool is_valid_tableau_move(pile_ref, pile_ref) const; @@ -69,11 +76,11 @@ private: // References to piles const sol_rules rules; - std::vector tableau_piles; - std::vector cells; + std::list tableau_piles; + std::list cells; pile_ref stock; pile_ref waste; - std::vector reserve; + std::list reserve; std::vector foundations; pile_ref hole; -- cgit v1.2.1 From 48f464b788ef0f2be539ec05b6e370ef46cfd015 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 30 Jan 2018 19:48:52 +0000 Subject: Add logic for ORDER_ON_CACHE to game_state --- src/main/game/game_state.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main/game/game_state.h') diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index fe43d99..532eefc 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -58,9 +58,11 @@ private: // Private constructor explicit game_state(const sol_rules&); +#ifndef ORDER_ON_CACHE // Used to maintain pile order invariant void eval_pile_order(pile_ref, bool); void eval_pile_order(std::list&, pile_ref, bool); +#endif // Used in get_legal_moves() move get_stock_tableau_move() const; -- cgit v1.2.1