-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrange.h
99 lines (81 loc) · 2.66 KB
/
range.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef GTO_RANGE_H_
#define GTO_RANGE_H_
#include <functional>
#include <string>
#include <unordered_set>
#include <vector>
#include <pokerstove/peval/Card.h>
#include "err.h"
#include "range_interface.h"
#include "state_interface.h"
namespace GTO {
// Represent hole cards.
class Hand : public CardSet, public StateInterface {
public:
Hand() : CardSet() {}
explicit Hand(const std::string& s)
: CardSet(s)
{
if (size() != 2)
err::quit("Hand should contain two cards: %s.",
s.c_str());
}
explicit Hand(const CardSet& c)
: CardSet(c)
{
if (size() != 2)
err::quit("Hand should contain two cards: %s.",
c.str().c_str());
}
bool operator<(const Hand& rhs) const
{
std::vector<pokerstove::Card> c1 = cards();
std::vector<pokerstove::Card> c2 = rhs.cards();
int t1 = (c1[0] < c1[1]) ? 1 : 0;
int t2 = (c2[0] < c2[1]) ? 1 : 0;
return c1[t1] < c2[t2] ||
(c1[t1] == c2[t2] && c1[1-t1]<c2[1-t2]);
}
static std::string Name() { return "Hand"; }
virtual std::string ToString() const { return str(); }
virtual unsigned short NumCombos() const { return 1; }
};
} // namespace GTO
namespace std {
template<>
struct hash<GTO::Hand> {
size_t
operator()(const GTO::Hand& h) const
{
return hash<uint64_t>()(h.mask());
}
};
} // namespace std
namespace GTO {
using std::string;
using std::vector;
// Implements a range of hands post-flop.
class Range : public RangeInterface<Hand> {
public:
typedef std::unordered_set<Hand>::const_iterator const_iterator;
Range() {};
explicit Range(const string& s);
virtual bool
IsMember(const Hand& hand) const
{
return range_.count(hand) > 0;
}
virtual void Add(const Hand& hand) { range_.insert(hand); }
virtual void Remove(const Hand& hand) { range_.erase(hand); }
virtual void Fill(const CardSet& dead_cards=CardSet());
virtual vector<Hand> ToVector(
const CardSet& dead_cards=CardSet()) const;
virtual string ToString() const;
virtual size_t Size() const { return range_.size(); }
const_iterator begin() const { return range_.begin();};
const_iterator end() const { return range_.end();};
private:
std::unordered_set<Hand> range_;
};
} // namespace GTO
#endif // !GTO_RANGE_H_