From 32a3c20c01266fc71a880a67d9693e5e1ded66c6 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Fri, 29 Dec 2017 21:49:21 +0000 Subject: Make game state representation efficient --- src/main/game/game_state.h | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 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 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 #include #include #include +#include #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 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 get_next_legal_states() const; + void make_move(move); + void undo_move(move); + std::vector get_legal_moves() const; bool is_solved() const; + const std::vector& get_data() const; std::ostream& print(std::ostream&) const; @@ -36,27 +45,29 @@ public: friend std::size_t hash_value(std::vector const&); private: - explicit game_state(const sol_rules&); + static std::vector gen_shuffled_deck(int, int); - static std::vector shuffled_deck(int, int); - - const game_state move(game_state&, pile*, pile*) const; - std::vector 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&) const; - void print_pile(std::ostream&, const pile&) const; - void print_top_of_piles(std::ostream&, const std::vector&) const; - void print_top_of_pile(std::ostream&, const pile&) const; + void print_piles(std::ostream&, const std::vector&) const; + void print_pile(std::ostream&, pile_ref) const; + void print_top_of_piles(std::ostream&, const std::vector&) const; + void print_top_of_pile(std::ostream&, pile_ref) const; sol_rules rules; - std::vector foundations; - std::vector cells; - std::vector tableau_piles; - pile reserve; - pile stock; - pile waste; - pile hole; + std::vector foundations; + std::vector cells; + std::vector tableau_piles; + pile_ref reserve; + pile_ref stock; + pile_ref waste; + pile_ref hole; + + std::vector addable_piles; + std::vector removable_piles; + + std::vector piles; }; -- cgit v1.2.1