-
Notifications
You must be signed in to change notification settings - Fork 3
/
helper.cpp
300 lines (281 loc) · 5.81 KB
/
helper.cpp
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*
* helper.cpp
*
* Created on: Dec 2, 2017
* Author: lowji
*/
#include "helper.h"
#include "Hand.h"
#include "Deck.h"
#include "Card.h"
#include <sstream>
using namespace std;
namespace std {
helper::helper() {
// TODO Auto-generated constructor stub
for (int i=0;i<13;i++){
for (int j=0;j<13;j++){
strengthChart[i][i]=0;
}
}
}
//method to determine if a string is an integer
bool helper::isInt(string input){
//Reference: https://stackoverflow.com/questions/20287186/how-to-check-if-the-input-is-a-valid-integer-without-any-other-chars
int x; //temporary int variable for checking input validity
char c; //temporary char variable for checking input validity
istringstream s(input);
if (!(s >> x)) {
return false;
}
if (s >> c) {
return false;
}
return true;
}
int helper::getStrength(Card* card1, Card* card2){
int num1=card1->getNumber();
int num2=card2->getNumber();
if (card1->getSuit()==card2->getSuit()){
return strengthChart[14-max(num1,num2)][14-min(num1,num2)];
}
else{
return strengthChart[14-min(num1,num2)][14-max(num1,num2)];
}
}
void helper::setStrengthChart(){
//https://howtoplaypokerinfo.com/wp-content/uploads/2016/06/Poker-cheat-sheet-card-printout-400x210.png
//setting strength 4
for (int i=0;i<13;i++){
strengthChart[i][i]=4;
}
for (int i=0;i<4;i++){
for (int j=0;j<5;j++){
strengthChart[i][j]=4;
}
}
//setting strength 3
strengthChart[4][0]=3;
strengthChart[3][1]=3;
strengthChart[3][2]=3;
strengthChart[1][4]=3;
strengthChart[2][4]=3;
strengthChart[3][4]=3;
strengthChart[4][5]=3;
//setting strength 2
for (int i=5;i<13;i++){
strengthChart[0][i]=2;
}
for (int i=1;i<4;i++){
strengthChart[i][5]=2;
}
for (int i=1;i<4;i++){
strengthChart[4][i]=2;
}
strengthChart[5][0]=2;
strengthChart[6][0]=2;
strengthChart[5][6]=2;
strengthChart[6][7]=2;
//setting strength 1
for (int i=1;i<5;i++){
strengthChart[i][6]=1;
}
strengthChart[1][7]=1;
strengthChart[5][7]=1;
strengthChart[6][8]=1;
strengthChart[7][9]=1;
strengthChart[7][8]=1;
strengthChart[8][9]=1;
strengthChart[9][10]=1;
for (int i=7;i<13;i++){
strengthChart[i][0]=1;
}
for (int i=5;i<8;i++){
strengthChart[i][1]=1;
}
for (int i=2;i<5;i++){
strengthChart[5][i]=1;
}
//print to test
/*for (int i=0;i<13;i++){
for (int j=0;j<13;j++){
cout<<strengthChart[i][j]<<"\t";
}
cout<<endl;
}*/
}
int helper::getPotential(int phase, Card card0, Card card1, Card card2, Card card3, Card card4, Card card5, Card card6)
{
if(phase == 2)
{
card5 = Card(1,4);
card6 = Card(0,4);
}
else if(phase == 3)
{
card6 = Card(0,4);
}
Hand* best = new Hand(card0,card1,card2,card3,card4);
Hand* comp;
int ori1;
int ori2;
for(int i = 0; i < 5; i++)
{
for(int j = i + 1; j < 6; j++)
{
vector<Card> temp6;
ori1 = i;
ori2 = j;
if(ori1 != 0 && ori2 != 0)
{
temp6.push_back(card0);
}
if(ori1 != 1 && ori2 != 1)
{
temp6.push_back(card1);
}
if(ori1 != 2 && ori2 != 2)
{
temp6.push_back(card2);
}
if(ori1 != 3 && ori2 != 3)
{
temp6.push_back(card3);
}
if(ori1 != 4 && ori2 != 4)
{
temp6.push_back(card4);
}
if(ori1 != 5 && ori2 != 5)
{
temp6.push_back(card5);
}
comp = new Hand(temp6[0],temp6[1],temp6[2],temp6[3],temp6[4]);
if(this->compareHands(comp,best) == 1)
{
best = comp;
}
}
}
return best->getType();
}
//returns 2 when they tie, 1 when hand1 wins, and 0 when hand 2 wins
int helper::compareHands(Hand* hand1, Hand* hand2)
{
int i = 2;
if(hand1->getType() > hand2->getType())
{
i = 1;
}
else if(hand1->getType() < hand2->getType())
{
i = 0;
}
else
{
if(hand1->getType() == 1 || hand1->getType() == 2)
{
if(hand1 -> getDoub() > hand2 -> getDoub())
{
i = 1;
}
else if(hand1 -> getDoub() < hand2 -> getDoub())
{
i = 0;
}
}
else if(hand1 -> getType() == 6 || hand1 -> getType() == 3)
{
if((hand1 -> getTrip())%100 > (hand2 -> getTrip())%100)
{
i = 1;
}
else if((hand1 -> getTrip())%100 < (hand2 -> getTrip())%100)
{
i = 0;
}
}
else if (hand1 -> getType() == 7)
{
if(hand1 -> getQuad() > hand2 -> getQuad())
{
i = 1;
}
else if(hand1->getQuad() < hand2->getQuad())
{
i = 0;
}
}
if(i == 2)
{
if(hand1 -> getHigh() > hand2 -> getHigh())
{
i = 1;
}
else if(hand1->getHigh() < hand2->getHigh())
{
i = 0;
}
}
}
return i;
}
//returns the highest value hand from a pool of 7 cards
Hand* helper::bestHand(Card card0, Card card1, Card card2, Card card3, Card card4, Card card5, Card card6)
{
Hand* best = new Hand(card0,card1,card2,card3,card4);
Hand* comp;
int ori1;
int ori2;
for(int i = 0; i < 6; i++)
{
for(int j = i + 1; j < 7; j++)
{
vector<Card> temp;
ori1 = i;
ori2 = j;
if(ori1 != 0 && ori2 != 0)
{
temp.push_back(card0);
}
if(ori1 != 1 && ori2 != 1)
{
temp.push_back(card1);
}
if(ori1 != 2 && ori2 != 2)
{
temp.push_back(card2);
}
if(ori1 != 3 && ori2 != 3)
{
temp.push_back(card3);
}
if(ori1 != 4 && ori2 != 4)
{
temp.push_back(card4);
}
if(ori1 != 5 && ori2 != 5)
{
temp.push_back(card5);
}
if(ori1 != 6 && ori2 != 6)
{
temp.push_back(card6);
}
comp = new Hand(temp[0],temp[1],temp[2],temp[3],temp[4]);
if(this->compareHands(comp,best) == 1)
{
best = comp;
}
}
}
return best;
}
} /* namespace std */
/*int main(){
helper* help=new helper();
help->setStrengthChart();
Card* one=new Card(12,1);
Card* two=new Card(11,2);
cout<<help->getStrength(one,two);
}*/