aboutsummaryrefslogtreecommitdiff
path: root/src/main/game/global_cache.h
diff options
context:
space:
mode:
authorCharlie Blake2018-02-02 13:04:33 +0000
committerGitHub2018-02-02 13:04:33 +0000
commit3eaf893c7edef511d5d6e7f4bbbf82fe5d1f1dce (patch)
tree2968ee1dc015a65a95d23e93afef764e88c8f36d /src/main/game/global_cache.h
parentMerge pull request #33 from thecharlesblake/fix-benchmark-bug (diff)
parentImprove printout of benchmark script (diff)
downloadmetasol-3eaf893c7edef511d5d6e7f4bbbf82fe5d1f1dce.tar.gz
metasol-3eaf893c7edef511d5d6e7f4bbbf82fe5d1f1dce.zip

Merge pull request #34 from thecharlesblake/reduced_state

Reduced state

Diffstat (limited to 'src/main/game/global_cache.h')
-rw-r--r--src/main/game/global_cache.h37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/main/game/global_cache.h b/src/main/game/global_cache.h
index 17585ed..4658e52 100644
--- a/src/main/game/global_cache.h
+++ b/src/main/game/global_cache.h
@@ -7,26 +7,40 @@
#include <vector>
#include <unordered_set>
+#include <boost/pool/pool.hpp>
+#include <boost/pool/pool_alloc.hpp>
#include "sol_rules.h"
#include "game_state.h"
-class predicate {
-public:
- explicit predicate(const game_state&);
- bool operator() (const std::vector<pile>&, const std::vector<pile>&) const;
-private:
- const game_state& init_gs;
+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&);
+ void add_pile(game_state::pile_ref, const game_state&);
+ void add_card(card, const game_state&);
+ void add_card_divider();
+
+ state_data data;
};
+bool operator==(const cached_game_state&, const cached_game_state&);
struct hasher {
explicit hasher(const game_state&);
- std::size_t operator() (const std::vector<pile>&) const;
+ 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;
- std::size_t combine_commutative(std::size_t&, std::size_t) const;
const game_state& init_gs;
};
@@ -39,12 +53,9 @@ public:
void clear();
private:
- static std::vector<pile> get_ordered_vec(const game_state&);
-
std::unordered_set<
- std::vector<pile>,
- hasher,
- predicate
+ cached_game_state,
+ hasher
> u_set;
};