From a2665d5958ec351a79246f95596280bc3874537b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 1 Feb 2018 12:59:45 +0000 Subject: Add game state reduction to cache --- src/main/game/global_cache.h | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/main/game/global_cache.h') diff --git a/src/main/game/global_cache.h b/src/main/game/global_cache.h index 17585ed..14691af 100644 --- a/src/main/game/global_cache.h +++ b/src/main/game/global_cache.h @@ -7,26 +7,47 @@ #include #include +#include +#include #include "sol_rules.h" #include "game_state.h" +struct cached_game_state { + typedef std::vector< +#ifdef NO_REDUCED_STATE + pile +#else + card +#endif + > state_data; + typedef state_data::size_type size_type; + + explicit cached_game_state(const game_state&); +#ifndef NO_REDUCED_STATE + void add_pile(const pile&, const game_state&); + void add_card(card, const game_state&); + void add_card_divider(); +#endif + + state_data data; +}; + class predicate { public: explicit predicate(const game_state&); - bool operator() (const std::vector&, const std::vector&) const; + bool operator() (const cached_game_state&, const cached_game_state&) const; private: const game_state& init_gs; }; struct hasher { explicit hasher(const game_state&); - std::size_t operator() (const std::vector&) const; + std::size_t operator() (const cached_game_state&) const; std::size_t hash_value(const card&) const; std::size_t hash_value(const pile&) const; std::size_t combine(std::size_t&, std::size_t) const; - std::size_t combine_commutative(std::size_t&, std::size_t) const; const game_state& init_gs; }; @@ -39,10 +60,8 @@ public: void clear(); private: - static std::vector get_ordered_vec(const game_state&); - std::unordered_set< - std::vector, + cached_game_state, hasher, predicate > u_set; -- cgit v1.2.1 From ac01aa9a755874e538fe5aadbdaa670f5d292ebc Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Fri, 2 Feb 2018 13:02:46 +0000 Subject: Simplify flagged versions of cached state --- src/main/game/global_cache.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/main/game/global_cache.h') diff --git a/src/main/game/global_cache.h b/src/main/game/global_cache.h index 14691af..4658e52 100644 --- a/src/main/game/global_cache.h +++ b/src/main/game/global_cache.h @@ -24,29 +24,22 @@ struct cached_game_state { typedef state_data::size_type size_type; explicit cached_game_state(const game_state&); -#ifndef NO_REDUCED_STATE - void add_pile(const pile&, const game_state&); + void add_pile(game_state::pile_ref, const game_state&); void add_card(card, const game_state&); void add_card_divider(); -#endif state_data data; }; - -class predicate { -public: - explicit predicate(const game_state&); - bool operator() (const cached_game_state&, const cached_game_state&) const; -private: - const game_state& init_gs; -}; +bool operator==(const cached_game_state&, const cached_game_state&); struct hasher { explicit hasher(const game_state&); std::size_t operator() (const cached_game_state&) const; std::size_t hash_value(const card&) const; +#ifdef NO_REDUCED_STATE std::size_t hash_value(const pile&) const; +#endif std::size_t combine(std::size_t&, std::size_t) const; const game_state& init_gs; @@ -62,8 +55,7 @@ public: private: std::unordered_set< cached_game_state, - hasher, - predicate + hasher > u_set; }; -- cgit v1.2.1