diff options
Diffstat (limited to 'src/main/game/global_cache.cpp')
| -rw-r--r-- | src/main/game/global_cache.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/main/game/global_cache.cpp b/src/main/game/global_cache.cpp index cc95b3b..f55a72c 100644 --- a/src/main/game/global_cache.cpp +++ b/src/main/game/global_cache.cpp @@ -5,7 +5,11 @@ #include "global_cache.h" -global_cache::global_cache(const sol_rules&) {} +typedef sol_rules::build_policy pol; + +global_cache::global_cache(const sol_rules& rules) { + global_cache::rules = rules; +} bool global_cache::insert(const std::vector<pile>& pile_vec) { return u_set.insert(pile_vec).second; @@ -14,3 +18,25 @@ bool global_cache::insert(const std::vector<pile>& pile_vec) { bool global_cache::contains(const std::vector<pile>& pile_vec) { return u_set.count(pile_vec) > 0; } + +size_t hash_value(card const& c) { + boost::hash<unsigned char> hasher; + + auto suit_val; + switch (global_cache::rules.build_pol) { + case pol::SAME_SUIT: + suit_val = static_cast<std::underlying_type_t<card::suit_t>>( + c.get_suit()); + break; + case pol::RED_BLACK: + suit_val = static_cast<std::underlying_type_t<card::colour_t >>( + c.get_colour()); + break; + default: + suit_val = 0; + break; + } + + auto raw_val = static_cast<unsigned char>(suit_val * 13 + c.get_rank()); + return hasher(raw_val); +} |
