diff options
| author | Charlie Blake | 2018-01-30 19:51:38 +0000 |
|---|---|---|
| committer | GitHub | 2018-01-30 19:51:38 +0000 |
| commit | 2fc005bdbb4707810ad0ae36a6863e70f0ff91b5 (patch) | |
| tree | 59ca3063ffe6a876d27c96ea95d6a3683273675a /src/main/game/game_state.h | |
| parent | Merge pull request #31 from thecharlesblake/profiling-fix (diff) | |
| parent | Add ORDER_ON_CACHE to benchmark script (diff) | |
| download | metasol-2fc005bdbb4707810ad0ae36a6863e70f0ff91b5.tar.gz metasol-2fc005bdbb4707810ad0ae36a6863e70f0ff91b5.zip | |
Merge pull request #32 from thecharlesblake/piles-always-sorted
Piles always sorted
Diffstat (limited to 'src/main/game/game_state.h')
| -rw-r--r-- | src/main/game/game_state.h | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index 8dcffa4..532eefc 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 <vector> +#include <list> #include <string> #include <rapidjson/document.h> @@ -18,7 +19,9 @@ class game_state { friend class deal_parser; friend class state_printer; - friend class game_state_pred; + friend class predicate; + friend class hasher; + friend class global_cache; public: // Defines types typedef uint8_t pile_ref; @@ -30,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<pile>); + // Does the same but with an initialiser list (useful for testing) + game_state(const sol_rules&, std::initializer_list<pile>); // Alters state void make_move(move); void undo_move(move); + void place_card(pile_ref, card); + card take_card(pile_ref); std::vector<move> get_legal_moves() const; @@ -48,16 +52,18 @@ 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<card> gen_shuffled_deck(int, card::rank_t, bool); // 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>&, pile_ref, bool); +#endif + // Used in get_legal_moves() move get_stock_tableau_move() const; bool is_valid_tableau_move(pile_ref, pile_ref) const; @@ -71,14 +77,20 @@ private: card) const; // References to piles - static sol_rules rules; - static std::vector<pile_ref> tableau_piles; - static std::vector<pile_ref> cells; - static pile_ref stock; - static pile_ref waste; - static std::vector<pile_ref> reserve; - static std::vector<pile_ref> foundations; - static pile_ref hole; + const sol_rules rules; + std::list<pile_ref> tableau_piles; + std::list<pile_ref> cells; + pile_ref stock; + pile_ref waste; + std::list<pile_ref> reserve; + std::vector<pile_ref> 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<pile_ref> original_tableau_piles; + std::vector<pile_ref> original_cells; + std::vector<pile_ref> original_reserve; // The core piles std::vector<pile> piles; |
