-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrange_utils.h
56 lines (43 loc) · 926 Bytes
/
range_utils.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
#ifndef GTO_RANGE_UTILS_H_
#define GTO_RANGE_UTILS_H_
#include <algorithm>
#include "err.h"
namespace GTO {
using std::string;
const string kRanks = "23456789TJQKA";
const string kSuits = "cdhs";
inline void
FmtError(const string& s)
{
err::quit("Unknown range format: %s.", s.c_str());
}
inline size_t
GetRank(char c)
{
return kRanks.find(c);
}
inline void
ParseRanks(const string& s, size_t pos, size_t& min, size_t& max)
{
std::pair<size_t,size_t> p = std::minmax(
GetRank(s[pos]), GetRank(s[pos+1]));
min = p.first;
max = p.second;
}
inline bool
IsSuit(char c)
{
return c == 'c' || c == 'd' || c == 'h' || c == 's';
}
inline bool
IsRank(char c)
{
return GetRank(c) != string::npos;
}
inline bool
IsHand(const string& s, size_t pos)
{
return IsRank(s[pos]) && IsRank(s[pos+1]);
}
} // namespace GTO
#endif // !GTO_RANGE_UTILS_H_