forked from emadrid-at-ccm/singulargy
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
182 lines (161 loc) · 5.91 KB
/
main.cpp
File metadata and controls
182 lines (161 loc) · 5.91 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "ep/Poker_io.h"
#include "ep/Poker.h"
#include "ep/Floyd.h"
#include "ep/Cases.h"
#ifdef TESTS
#define CATCH_CONFIG_MAIN
#else
#define CATCH_CONFIG_RUNNER
#endif
#include "catch.hpp"
TEST_CASE("Classification generation", "[bit]") {
SECTION("SuitedPocket") {
using namespace ep;
using namespace abbreviations;
SuitedPocket sp;
REQUIRE(0x11 == sp.next());
REQUIRE(bool(sp));
REQUIRE(0x101 == sp.next());
REQUIRE(0x110 == sp.next());
sp.m_current = 3 << 11;
REQUIRE((sA | sK) == sp.next());
REQUIRE(!sp);
}
SECTION("PocketPair") {
using namespace ep;
using namespace abbreviations;
PocketPair pp;
REQUIRE((s2 | h2) == pp.next());
REQUIRE((s3 | h3) == pp.next());
pp.m_current = sA;
REQUIRE(bool(pp));
pp.next();
REQUIRE(!pp);
}
SECTION("SuitedPocket") {
using namespace ep;
using namespace abbreviations;
UnsuitedPocket sp;
REQUIRE((s3 | h2) == sp.next());
REQUIRE(bool(sp));
REQUIRE((s4 | h2) == sp.next());
REQUIRE((s4 | h3) == sp.next());
sp.m_current = 3 << 11;
REQUIRE((sA | hK) == sp.next());
REQUIRE(!sp);
}
}
constexpr uint64_t royalFlush() {
using namespace ep::abbreviations;
return hA | hK | hQ | hJ | hT;
}
TEST_CASE("Bit operations", "[bit]") {
auto sevenNibbles = ep::core::makeBitmask<4, uint64_t>(7);
auto octals = 01234567ull;
auto deposited = __builtin_ia32_pdep_di(octals, sevenNibbles);
REQUIRE(0x1234567 == deposited);
auto alreadySet = 0xC63; // 1 1 0 0 .0 1 1 0 .0 0 1 1
auto interleave = 0x2A; // 1a0b.1c0d1e0f
auto expected = 0xEEB; // 1 1 1a0b.1c1 1 0d.1e0f1 1
auto byEp = ep::core::deposit(alreadySet, interleave);
byEp |= alreadySet;
REQUIRE(expected == byEp);
}
TEST_CASE("Poker operations", "[basic]") {
using namespace ep::abbreviations;
SECTION("HandRank equality") {
ep::HandRank hr1(ep::HIGH_CARDS, 1, 0);
ep::HandRank hr2(ep::HIGH_CARDS, 2, 0);
auto equal = hr1 == hr2;
REQUIRE(!equal);
}
SECTION("Flush") {
auto noFlush = sQ;
REQUIRE(0 == ep::flush(noFlush));
auto flushOfDiamonds = dK | dT | d7 | d6 | d2;
auto sevenCardFlush5x2 = noFlush | sA | flushOfDiamonds;
auto flush = ep::flush(sevenCardFlush5x2);
auto flushOfClubs = flushOfDiamonds >> (sD - sS);
REQUIRE(flush == flushOfClubs);
auto heartsRoyalFlush = royalFlush();
auto hrf = ep::SWARRank(heartsRoyalFlush);
auto hrcounted = ep::RankCounts(hrf);
auto present = hrcounted.greaterEqual<1>();
auto straightsResult = ep::straights_rankRepresentation(present);
REQUIRE(rA == straightsResult.top());
}
SECTION("Straight") {
auto straightTo5 = (royalFlush() ^ hT) | d2 | c3 | d4 | s5;
auto sr5 = ep::SWARRank(straightTo5);
auto p5 = ep::RankCounts(sr5);
auto p5Present = p5.greaterEqual<1>();
auto straightTo5Result = ep::straights_rankRepresentation(p5Present);
REQUIRE(r5 == straightTo5Result.top());
auto no = straightTo5 ^ s5;
auto noRanks = ep::RankCounts(ep::SWARRank(no)).greaterEqual<1>();
auto notStraight = ep::straights_rankRepresentation(noRanks);
REQUIRE(!notStraight);
}
}
TEST_CASE("Hands", "[basic]") {
using namespace ep::abbreviations;
SECTION("Straight Flush") {
auto straightFlushCards = h4 | h5 | h6 | h7 | h8 | c8 | d8;
auto result = ep::handRank(straightFlushCards);
REQUIRE(ep::STRAIGHT_FLUSH == result.hand);
REQUIRE(0 == result.high);
REQUIRE((1 << r8) == result.low);
}
SECTION("Four of a kind") {
auto foakCards = s5 | h5 | d5 | c5 | sK | cK | hK;
auto result = ep::handRank(foakCards);
REQUIRE(ep::FOUR_OF_A_KIND == result.hand);
REQUIRE((1 << r5) == result.high);
REQUIRE((1 << rK) == result.low);
}
SECTION("Full House") {
auto threysOverKings = s3 | d3 | h3 | dK | cK | sA | dQ;
auto r = ep::handRank(threysOverKings);
REQUIRE(ep::HandRank(ep::FULL_HOUSE, 0 | r3, 0 | rK) == r);
auto doubleToak = s3 | d3 | h3 | hA | dA | cA | dK;
auto acesOverThreys = ep::handRank(doubleToak);
REQUIRE(ep::HandRank(ep::FULL_HOUSE, 0 | rA, 0 | r3) == acesOverThreys);
}
SECTION("Flush") {
auto baseFlush = (royalFlush() ^ hA) | h8;
auto extraKings = sK | cK;
auto wholeHand = baseFlush | extraKings;
auto r = ep::handRank(wholeHand);
auto kqjt8 = ep::HandRank(ep::FLUSH, 0, rK | rQ | rJ | rT | r8);
REQUIRE(kqjt8 == r);
auto withoutTOAK = baseFlush | h5 | h4;
auto without = ep::handRank(withoutTOAK);
REQUIRE(kqjt8 == without);
}
SECTION("Straight") {
auto fromAce = sA | h2 | d3 | c4 | s5 | d5 | c5;
auto r = ep::handRank(fromAce);
REQUIRE(ep::HandRank(ep::STRAIGHT, 0, 0 | r5) == r);
}
SECTION("Three of a kind") {
auto threysOverAceKing = (royalFlush() ^ hT) | s3 | d3 | c3;
auto r = ep::handRank(threysOverAceKing);
REQUIRE(ep::HandRank(ep::THREE_OF_A_KIND, 0 | r3, rA | rK) == r);
}
SECTION("Two Pairs") {
auto kingsOverTensAceHigh = (royalFlush() ^ hJ) | cK | cT | c9;
auto r = ep::handRank(kingsOverTensAceHigh);
REQUIRE(ep::HandRank(ep::TWO_PAIRS, rK | rT, 0 | rA) == r);
}
SECTION("Pairs") {
auto hooks = (royalFlush() ^ hA) | cJ | s2 | s3;
auto r = ep::handRank(hooks);
ep::HandRank comparator(ep::PAIR, 0 | rJ, rK | rQ | rT);
REQUIRE(comparator == r);
}
SECTION("High Cards") {
auto nothing = (royalFlush() ^ hA) | c8 | c7 | c6;
auto r = ep::handRank(nothing);
REQUIRE(ep::HandRank(ep::HIGH_CARDS, 0, rK | rQ | rJ | rT | r8) == r);
}
}