diff options
| author | Charlie Blake | 2017-12-31 11:53:50 +0000 |
|---|---|---|
| committer | GitHub | 2017-12-31 11:53:50 +0000 |
| commit | 22e8b69a830d3e61be83762b9f1e6ce97bd3ec1e (patch) | |
| tree | faa726d97fcde3ea236f46e0c2b2d77a68f4cd9f /src/main/game/game_state.h | |
| parent | Merge pull request #26 from thecharlesblake/deal-description-and-test (diff) | |
| parent | Remove need for default switch in compile flags (diff) | |
| download | metasol-22e8b69a830d3e61be83762b9f1e6ce97bd3ec1e.tar.gz metasol-22e8b69a830d3e61be83762b9f1e6ce97bd3ec1e.zip | |
Merge pull request #27 from thecharlesblake/efficient-implementation
Efficient implementation
Diffstat (limited to 'src/main/game/game_state.h')
| -rw-r--r-- | src/main/game/game_state.h | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index 4b96b72..8adc9d6 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -5,11 +5,14 @@ #ifndef SOLVITAIRE_GAME_STATE_H #define SOLVITAIRE_GAME_STATE_H +#define NULL_MOVE (game_state::move(255, 255)) + #include <vector> #include <ostream> #include <string> #include <rapidjson/document.h> +#include <boost/functional/hash.hpp> #include "card.h" #include "sol_rules.h" @@ -20,13 +23,19 @@ class deal_parser; class game_state { friend class deal_parser; public: + typedef uint8_t pile_ref; + typedef std::pair<pile_ref, pile_ref> move; + // Create a game state representation from a JSON doc game_state(const sol_rules&, const rapidjson::Document&); // Do the same from a 'rules' object game_state(const sol_rules&, int seed); - const std::vector<game_state> get_next_legal_states() const; + void make_move(move); + void undo_move(move); + std::vector<move> get_legal_moves() const; bool is_solved() const; + const std::vector<pile>& get_data() const; std::ostream& print(std::ostream&) const; @@ -36,27 +45,29 @@ public: friend std::size_t hash_value(std::vector<pile> const&); private: - explicit game_state(const sol_rules&); + static std::vector<card> gen_shuffled_deck(int, int); - static std::vector<card> shuffled_deck(int, int); - - const game_state move(game_state&, pile*, pile*) const; - std::vector<pile*> get_regular_pile_refs(); + explicit game_state(const sol_rules&); void print_header(std::ostream&, const char*) const; - void print_piles(std::ostream&, const std::vector<pile>&) const; - void print_pile(std::ostream&, const pile&) const; - void print_top_of_piles(std::ostream&, const std::vector<pile>&) const; - void print_top_of_pile(std::ostream&, const pile&) const; + void print_piles(std::ostream&, const std::vector<pile_ref>&) const; + void print_pile(std::ostream&, pile_ref) const; + void print_top_of_piles(std::ostream&, const std::vector<pile_ref>&) const; + void print_top_of_pile(std::ostream&, pile_ref) const; sol_rules rules; - std::vector<pile> foundations; - std::vector<pile> cells; - std::vector<pile> tableau_piles; - pile reserve; - pile stock; - pile waste; - pile hole; + std::vector<pile_ref> foundations; + std::vector<pile_ref> cells; + std::vector<pile_ref> tableau_piles; + pile_ref reserve; + pile_ref stock; + pile_ref waste; + pile_ref hole; + + std::vector<pile_ref> addable_piles; + std::vector<pile_ref> removable_piles; + + std::vector<pile> piles; }; |
