From 895bbca6c0c7233fe11f331a10135443970ec4c5 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Fri, 12 Jan 2018 18:05:07 +0000 Subject: Implement hash for piles --- src/main/game/global_cache.cpp | 8 ++++++++ src/main/game/global_cache.h | 1 + src/main/game/pile.cpp | 7 ------- src/main/game/pile.h | 2 ++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/game/global_cache.cpp b/src/main/game/global_cache.cpp index f55a72c..e881408 100644 --- a/src/main/game/global_cache.cpp +++ b/src/main/game/global_cache.cpp @@ -2,8 +2,12 @@ // Created by thecharlesblake on 1/10/18. // +#include + #include "global_cache.h" +using namespace std; +using namespace boost; typedef sol_rules::build_policy pol; @@ -40,3 +44,7 @@ size_t hash_value(card const& c) { auto raw_val = static_cast(suit_val * 13 + c.get_rank()); return hasher(raw_val); } + +size_t hash_value(pile const& p) { + return hash_range(begin(p.pile_vec), end(p.pile_vec)); +} diff --git a/src/main/game/global_cache.h b/src/main/game/global_cache.h index a5c6768..26a73ef 100644 --- a/src/main/game/global_cache.h +++ b/src/main/game/global_cache.h @@ -21,6 +21,7 @@ public: friend std::size_t hash_value(card const&); private: static sol_rules rules; + std::unordered_set< std::vector, boost::hash> diff --git a/src/main/game/pile.cpp b/src/main/game/pile.cpp index ad7b85e..ba7c1b9 100644 --- a/src/main/game/pile.cpp +++ b/src/main/game/pile.cpp @@ -5,12 +5,9 @@ #include #include -#include - #include "pile.h" using namespace std; -using namespace boost; pile::pile(std::vector pv) : pile_vec(pv) {} @@ -49,7 +46,3 @@ card pile::take() { bool operator==(const pile& a, const pile& b) { return a.pile_vec == b.pile_vec; } - -size_t hash_value(pile const& p) { - return hash_range(begin(p.pile_vec), end(p.pile_vec)); -} diff --git a/src/main/game/pile.h b/src/main/game/pile.h index fb7bc38..ab661ca 100644 --- a/src/main/game/pile.h +++ b/src/main/game/pile.h @@ -29,6 +29,8 @@ public: card& operator[] (size_type); card operator[] (size_type) const; + + friend bool operator==(const pile&, const pile&); friend std::size_t hash_value(pile const&); private: -- cgit v1.2.1