diff options
| author | thecharlesblake | 2018-01-03 12:30:14 +0000 |
|---|---|---|
| committer | thecharlesblake | 2018-01-03 12:30:14 +0000 |
| commit | 77a7aeba7854d15b140cc6dc3c69b15ed5f3b936 (patch) | |
| tree | 70b3b8315646ed38000a1627ec3f3efe20f31f92 /src/main/game/game_state.h | |
| parent | Update idea to python3 (diff) | |
| download | metasol-77a7aeba7854d15b140cc6dc3c69b15ed5f3b936.tar.gz metasol-77a7aeba7854d15b140cc6dc3c69b15ed5f3b936.zip | |
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.
Diffstat (limited to 'src/main/game/game_state.h')
| -rw-r--r-- | src/main/game/game_state.h | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/main/game/game_state.h b/src/main/game/game_state.h index 8adc9d6..28d849e 100644 --- a/src/main/game/game_state.h +++ b/src/main/game/game_state.h @@ -5,7 +5,8 @@ #ifndef SOLVITAIRE_GAME_STATE_H #define SOLVITAIRE_GAME_STATE_H -#define NULL_MOVE (game_state::move(255, 255)) +#define NULL_MOVE (game_state::move(PILE_REF_MAX, PILE_REF_MAX)) +#define PILE_REF_MAX (255) #include <vector> #include <ostream> @@ -15,28 +16,35 @@ #include <boost/functional/hash.hpp> #include "card.h" -#include "sol_rules.h" #include "pile.h" +#include "sol_rules.h" class deal_parser; class game_state { friend class deal_parser; public: + // Defines types typedef uint8_t pile_ref; typedef std::pair<pile_ref, pile_ref> move; - // Create a game state representation from a JSON doc + // Constructors + // Creates a game state representation from a JSON doc game_state(const sol_rules&, const rapidjson::Document&); - // Do the same from a 'rules' object + // Does the same from a 'rules' object game_state(const sol_rules&, int seed); + // Alters state void make_move(move); void undo_move(move); + std::vector<move> get_legal_moves() const; + + // Inspects state bool is_solved() const; const std::vector<pile>& get_data() const; + // Prints std::ostream& print(std::ostream&) const; friend bool operator==(const game_state&, const game_state&); @@ -47,26 +55,31 @@ public: private: static std::vector<card> gen_shuffled_deck(int, int); + // Private constructor explicit game_state(const sol_rules&); + // Used in get_legal_moves() + bool is_valid_tableau_move(pile_ref, pile_ref) const; + bool is_valid_foundations_move(pile_ref, pile_ref) const; + bool is_valid_hole_move(pile_ref) const; + + // Prints void print_header(std::ostream&, const char*) 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; + // References to piles sol_rules rules; - std::vector<pile_ref> foundations; - std::vector<pile_ref> cells; std::vector<pile_ref> tableau_piles; - pile_ref reserve; + std::vector<pile_ref> cells; pile_ref stock; pile_ref waste; + std::vector<pile_ref> foundations; pile_ref hole; - std::vector<pile_ref> addable_piles; - std::vector<pile_ref> removable_piles; - + // The core piles std::vector<pile> piles; }; |
