forked from Fossana/cplusplus-cfr-poker-solver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.cpp
More file actions
160 lines (136 loc) · 3.22 KB
/
State.cpp
File metadata and controls
160 lines (136 loc) · 3.22 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
#include "State.h"
#include <iostream>
using std::make_unique;
using std::move;
using std::cout;
State::State()
{
}
State::State(State& state)
{
street = state.street;
potSize = state.potSize;
for (int i = 0; i < 5; i++)
board[i] = state.board[i];
p1 = make_unique<PlayerState>(*state.p1);
p2 = make_unique<PlayerState>(*state.p2);
if (state.current->id == 1)
current = p1.get();
else
current = p2.get();
if (state.lastToAct->id == 1)
lastToAct = p1.get();
else
lastToAct = p2.get();
minimumRaiseSize = state.minimumRaiseSize;
minimumBetSize = state.minimumBetSize;
}
int State::get_highest_wager()
{
if (p1->wager > p2->wager)
return p1->wager;
return p2->wager;
}
int State::get_call_amount()
{
return get_highest_wager() - current->wager;
}
bool State::is_uncontested()
{
return p1->hasFolded || p2->hasFolded;
}
bool State::both_players_are_allin()
{
return p1->is_allin() && p2->is_allin();
}
bool State::apply_player_action(Action& action)
{
if (action.type == ActionType::FOLD)
{
current->hasFolded = true;
potSize -= get_call_amount();
return true;
}
else if (action.type == ActionType::CHECK)
{
if (current == lastToAct)
return true;
}
else if (action.type == ActionType::CALL)
{
current->commit_chips(action.amount);
potSize += action.amount;
return true;
}
else if (action.type == ActionType::BET)
{
current->commit_chips(action.amount);
potSize += action.amount;
minimumRaiseSize = action.amount;
reset_lastToAct();
}
else if (action.type == ActionType::RAISE)
{
int chipsToCommit = action.amount - current->wager;
current->commit_chips(chipsToCommit);
potSize += chipsToCommit;
int raiseSize = action.amount - get_highest_wager();
if (raiseSize > minimumRaiseSize)
minimumRaiseSize = raiseSize;
reset_lastToAct();
}
update_current();
return false;
}
void State::go_to_next_street()
{
if (street == Street::FLOP)
street = Street::TURN;
else if (street == Street::TURN)
street = Street::RIVER;
p1->reset_wager();
p2->reset_wager();
initialize_current();
initialize_lastToAct();
minimumRaiseSize = minimumBetSize;
}
void State::initialize_current()
{
if (!p1->hasPosition)
current = p1.get();
else
current = p2.get();
}
void State::initialize_lastToAct()
{
if (p1->hasPosition)
lastToAct = p1.get();
else
lastToAct = p2.get();
}
void State::update_current()
{
if (current == p1.get())
current = p2.get();
else
current = p1.get();
}
void State::reset_lastToAct()
{
if (lastToAct == p1.get())
lastToAct = p2.get();
else
lastToAct = p1.get();
}
int State::get_current_wager()
{
return current->wager;
}
int State::get_current_stack()
{
return current->stackSize;
}
int State::get_current_id()
{
return current->id;
}