-
Notifications
You must be signed in to change notification settings - Fork 14
/
info.cpp
334 lines (273 loc) · 7.36 KB
/
info.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
OOPoker
Copyright (c) 2010 Lode Vandevenne
All rights reserved.
This file is part of OOPoker.
OOPoker is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OOPoker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OOPoker. If not, see <http://www.gnu.org/licenses/>.
*/
#include "info.h"
#include "pokermath.h"
#include "action.h"
#include "util.h"
PlayerInfo::PlayerInfo()
: showdown(false)
{
}
const std::string& PlayerInfo::getName() const
{
return name;
}
bool PlayerInfo::isAllIn() const
{
return stack == 0 && wager != 0;
}
bool PlayerInfo::isOut() const
{
return stack == 0 && wager == 0;
}
bool PlayerInfo::isFolded() const
{
return folded;
}
bool PlayerInfo::canDecide() const
{
return stack > 0 && !folded;
}
Info::Info()
{
}
const std::vector<Card>& Info::getHoleCards() const
{
return players[yourIndex].holeCards;
}
int Info::getPosition() const
{
return wrap(yourIndex - dealer);
}
int Info::getNumPlayers() const
{
return players.size();
}
std::vector<Card> Info::getHandTableVector() const
{
std::vector<Card> result;
result.insert(result.end(), getHoleCards().begin(), getHoleCards().end());
result.insert(result.end(), boardCards.begin(), boardCards.end());
return result;
}
int Info::wrap(int index) const
{
return ::wrap(index, players.size());
}
int Info::getPot() const
{
int result = 0;
for(size_t i = 0; i < players.size(); i++)
{
result += players[i].wager;
}
return result;
}
int Info::getHighestWager() const
{
int result = 0;
for(size_t i = 0; i < players.size(); i++)
{
if(players[i].wager > result) result = players[i].wager;
}
return result;
}
int Info::getCallAmount() const
{
return getCallAmount(yourIndex);
}
int Info::getMinChipsToRaise() const
{
return getMinChipsToRaise(yourIndex);
}
Action Info::amountToAction(int amount) const
{
if(amount > getStack()) return getAllInAction();
int call = getCallAmount();
int raise = minRaiseAmount + call;
if(amount < 0)
{
return Action(A_FOLD);
}
else if(amount < call)
{
return Action(A_FOLD);
}
else if(amount == 0 && call == 0)
{
return Action(A_CHECK);
}
else if(amount == call)
{
return Action(A_CALL);
}
else if(amount > call && amount < raise)
{
return Action(A_CALL); //amount too small for the min raise rule
}
else if(amount > call)
{
return Action(A_RAISE, amount);
}
else return Action(A_FOLD); //normally you never get here
}
int Info::getStack() const
{
return players[yourIndex].stack;
}
int Info::getWager() const
{
return players[yourIndex].wager;
}
double Info::getMRatio() const
{
/*
From Wikipedia (Herrington Zones):
M-ratio Zone name "Optimal" strategy
M >= 20 Green zone Most desirable situation, freedom to play conservatively or aggressively as you choose
10 <= M < 20 Yellow zone Must take on more risk, hands containing small pairs and small suited connectors lose value
6 <= M < 10 Orange zone Main focus is to be first-in whatever you decide to play, important to preserve chips
1 <= M < 6 Red zone Your only move is to move all-in or fold
M < 1 Dead zone You are completely dependent on luck to survive, the only strategy is to push all-in into an empty pot
*/
return getMRatio(yourIndex);
}
double Info::getPotOdds() const
{
return getPotOdds(yourIndex);
}
double Info::getPotOddsPercentage() const
{
return getPotOddsPercentage(yourIndex);
}
double Info::getPotEquity() const
{
return getPotEquity(yourIndex);
}
bool Info::isValidAllInAction(const Action& action) const
{
return ::isValidAllInAction(action, getStack(), getWager(), getHighestWager(), minRaiseAmount);
}
bool Info::isValidAction(const Action& action) const
{
return ::isValidAction(action, getStack(), getWager(), getHighestWager(), minRaiseAmount);
}
Action Info::getRaiseAction(int raise) const
{
return amountToAction(raise + getCallAmount());
}
Action Info::getAllInAction() const
{
if(getStack() > getCallAmount()) return Action(A_RAISE, getStack());
else return getCallAction();
}
Action Info::getCheckFoldAction() const
{
return amountToAction(0);
}
Action Info::getCallAction() const
{
return getCallAmount() == 0 ? Action(A_CHECK) : Action(A_CALL);
}
const PlayerInfo& Info::getYou() const
{
return players[yourIndex];
}
int Info::getNumActivePlayers() const
{
int result = 0;
for(size_t i = 0; i < players.size(); i++)
{
if(!players[i].folded) result++;
}
return result;
}
int Info::getNumDecidingPlayers() const
{
int result = 0;
for(size_t i = 0; i < players.size(); i++)
{
if(players[i].canDecide()) result++;
}
return result;
}
int Info::getSmallBlind() const
{
return rules.smallBlind;
}
int Info::getBigBlind() const
{
return rules.bigBlind;
}
bool Info::isGlobal() const
{
return yourIndex < 0;
}
////////////////////////////////////////////////////////////////////////////////
int Info::getCallAmount(int index) const
{
int result = getHighestWager() - players[index].wager;
if(getStack(index) < result) result = getStack(index);
return result;
}
int Info::getMinChipsToRaise(int index) const
{
return getCallAmount(index) + minRaiseAmount;
}
int Info::getStack(int index) const
{
return players[index].stack;
}
int Info::getWager(int index) const
{
return players[index].wager;
}
double Info::getMRatio(int index) const
{
/*
From Wikipedia (Herrington Zones):
M-ratio Zone name "Optimal" strategy
M >= 20 Green zone Most desirable situation, freedom to play conservatively or aggressively as you choose
10 <= M < 20 Yellow zone Must take on more risk, hands containing small pairs and small suited connectors lose value
6 <= M < 10 Orange zone Main focus is to be first-in whatever you decide to play, important to preserve chips
1 <= M < 6 Red zone Your only move is to move all-in or fold
M < 1 Dead zone You are completely dependent on luck to survive, the only strategy is to push all-in into an empty pot
*/
return ((double)getStack(index)) / (rules.smallBlind + rules.bigBlind + rules.ante * players.size());
}
double Info::getPotOdds(int index) const
{
return (double)getPot() / (double)getCallAmount(index);
}
double Info::getPotOddsPercentage(int index) const
{
double c = getCallAmount(index);
return c / ((double)getPot() + c);
}
double Info::getPotEquity(int index) const
{
int numOpponents = getNumActivePlayers() - 1;
return ::getPotEquity(getHoleCards(index), boardCards, numOpponents);
}
int Info::getPosition(int index) const
{
return wrap(index - dealer);
}
const std::vector<Card>& Info::getHoleCards(int index) const
{
return players[index].holeCards;
}