aboutsummaryrefslogtreecommitdiff
path: root/src/main/game/global_cache.h
diff options
context:
space:
mode:
authorCharlie Blake2018-01-30 19:51:38 +0000
committerGitHub2018-01-30 19:51:38 +0000
commit2fc005bdbb4707810ad0ae36a6863e70f0ff91b5 (patch)
tree59ca3063ffe6a876d27c96ea95d6a3683273675a /src/main/game/global_cache.h
parentMerge pull request #31 from thecharlesblake/profiling-fix (diff)
parentAdd ORDER_ON_CACHE to benchmark script (diff)
downloadmetasol-2fc005bdbb4707810ad0ae36a6863e70f0ff91b5.tar.gz
metasol-2fc005bdbb4707810ad0ae36a6863e70f0ff91b5.zip

Merge pull request #32 from thecharlesblake/piles-always-sorted

Piles always sorted

Diffstat (limited to 'src/main/game/global_cache.h')
-rw-r--r--src/main/game/global_cache.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/main/game/global_cache.h b/src/main/game/global_cache.h
index 486006c..17585ed 100644
--- a/src/main/game/global_cache.h
+++ b/src/main/game/global_cache.h
@@ -8,27 +8,43 @@
#include <vector>
#include <unordered_set>
-#include <boost/functional/hash.hpp>
-
#include "sol_rules.h"
#include "game_state.h"
-struct game_state_pred {
- static bool comp_pile(const pile& x, const pile& y);
- bool operator() (const game_state& x, const game_state& y)
- const;
+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 hasher {
+ explicit hasher(const game_state&);
+ std::size_t operator() (const std::vector<pile>&) 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;
};
class global_cache {
public:
+ explicit global_cache(const game_state&);
bool insert(const game_state&);
bool contains(const game_state&) const;
void clear();
+
private:
+ static std::vector<pile> get_ordered_vec(const game_state&);
+
std::unordered_set<
- game_state,
- boost::hash<game_state>,
- game_state_pred
+ std::vector<pile>,
+ hasher,
+ predicate
> u_set;
};