-
Notifications
You must be signed in to change notification settings - Fork 14
/
event.cpp
259 lines (227 loc) · 9.26 KB
/
event.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
/*
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 "event.h"
#include "combination.h"
#include "player.h"
#include "observer.h"
#include <sstream>
Event::Event(EventType type)
: type(type)
{
}
Event::Event(EventType type, const std::string& player)
: type(type)
, player(player)
{
}
Event::Event(EventType type, const std::string& player, int chips)
: type(type)
, player(player)
, chips(chips)
{
}
Event::Event(EventType type, int position, const std::string& player)
: type(type)
, player(player)
, position(position)
{
}
Event::Event(EventType type, int position, int chips, const std::string& player)
: type(type)
, player(player)
, chips(chips)
, position(position)
{
}
Event::Event(EventType type, const std::string& player, const std::string& ai)
: type(type)
, player(player)
, ai(ai)
{
}
Event::Event(EventType type, const Card& card1)
: type(type)
, card1(card1)
{
}
Event::Event(EventType type, const Card& card1, const Card& card2)
: type(type)
, card1(card1)
, card2(card2)
{
}
Event::Event(EventType type, const Card& card1, const Card& card2, const Card& card3)
: type(type)
, card1(card1)
, card2(card2)
, card3(card3)
{
}
Event::Event(EventType type, const Card& card1, const Card& card2, const Card& card3, const Card& card4)
: type(type)
, card1(card1)
, card2(card2)
, card3(card3)
, card4(card4)
{
}
Event::Event(EventType type, const Card& card1, const Card& card2, const Card& card3, const Card& card4, const Card& card5)
: type(type)
, card1(card1)
, card2(card2)
, card3(card3)
, card4(card4)
, card5(card5)
{
}
Event::Event(EventType type, const std::string& player, const Card& card1, const Card& card2, const Card& card3, const Card& card4, const Card& card5)
: type(type)
, player(player)
, card1(card1)
, card2(card2)
, card3(card3)
, card4(card4)
, card5(card5)
{
}
Event::Event(EventType type, const std::string& player, const Card& card1, const Card& card2)
: type(type)
, player(player)
, card1(card1)
, card2(card2)
{
}
Event::Event(const std::string& message, EventType type)
: type(type)
, message(message)
{
}
Event::Event(EventType type, int smallBlind, int bigBlind, int ante)
: type(type)
, smallBlind(smallBlind)
, bigBlind(bigBlind)
, ante(ante)
{
}
std::string eventToString(const Event& event)
{
std::stringstream ss;
std::string playerName = event.player;
switch(event.type)
{
case E_JOIN: ss << "Joins: " << playerName << ", chips: " << event.chips; break;
case E_QUIT: ss << "Quits: " << playerName << ", chips: " << event.chips; break;
case E_REBUY: ss << "Player " << playerName << " rebuys with " << event.chips << " chips"; break;
case E_SMALL_BLIND: ss << "Small Blind: " << playerName << ", chips: " << event.chips; break;
case E_BIG_BLIND: ss << "Big Blind: " << playerName << ", chips: " << event.chips; break;
case E_ANTE: ss << "Ante: " << playerName << ", chips: " << event.chips; break;
case E_FOLD: ss << "Folds: " << playerName ; break;
case E_CHECK: ss << "Checks: " << playerName; break;
case E_CALL: ss << "Calls: " << playerName; break;
case E_RAISE: ss << "Raises: " << playerName << ", chips: " << event.chips; break;
case E_NEW_DEAL: ss << "New deal." << " SB: " << event.smallBlind << " BB: " << event.bigBlind << " Ante: " << event.ante; break;
case E_RECEIVE_CARDS: ss << "Received cards: " << event.card1.getShortName() << " " << event.card2.getShortName(); break;
case E_FLOP: ss << "Flop: " << event.card1.getShortName() << " " << event.card2.getShortName() << " " << event.card3.getShortName(); break;
case E_TURN: ss << "Turn: " << event.card4.getShortName(); break;
case E_RIVER: ss << "River: " << event.card5.getShortName(); break;
case E_SHOWDOWN: ss << "Showdown Reached"; break;
case E_POT_DIVISION: ss << "Pot size: " << event.chips; break;
case E_WIN: ss << "Wins: " << playerName << ", chips: " << event.chips; break;
case E_PLAYER_SHOWDOWN: ss << "Shows: " << playerName << ", " << event.card1.getShortName() << " " << event.card2.getShortName(); break;
case E_BOAST: ss << "Boasts: " << playerName << ", " << event.card1.getShortName() << " " << event.card2.getShortName(); break;
case E_COMBINATION:
{
Combination combo;
getCombo(combo, event.card1, event.card2, event.card3, event.card4, event.card5);
ss << "Combination: " << playerName << ", " << combo.getNameWithAllCards();
break;
}
case E_DEALER: ss << "Dealer: " << playerName; break;
case E_TOURNAMENT_RANK: ss << "Ranking: " << playerName << ", Place: " << event.position << ", Score: " << event.chips; break;
case E_REVEAL_AI: ss << "Reveal AI: " << playerName << ", AI: " << event.ai; break;
case E_LOG_MESSAGE: ss << event.message; break;
case E_DEBUG_MESSAGE: ss << "DEBUG MESSAGE: " << event.message; break;
default: ss << "??????";
}
return ss.str();
}
std::string eventToStringVerbose(const Event& event)
{
std::stringstream ss;
std::string playerName = event.player;
switch(event.type)
{
case E_JOIN: ss << "Player " << playerName << " joins with " << event.chips << " chips"; break;
case E_QUIT: ss << "Player " << playerName << " leaves with " << event.chips << " chips"; break;
case E_REBUY: ss << "Player " << playerName << " rebuys with " << event.chips << " chips"; break;
case E_SMALL_BLIND: ss << "Player " << playerName << " places the small blind (" << event.chips << ")"; break;
case E_BIG_BLIND: ss << "Player " << playerName << " places the big blind (" << event.chips << ")"; break;
case E_ANTE: ss << "Player " << playerName << " places ante (" << event.chips << ")"; break;
case E_FOLD: ss << "Player " << playerName << " folds."; break;
case E_CHECK: ss << "Player " << playerName << " checks."; break;
case E_CALL: ss << "Player " << playerName << " calls."; break;
case E_RAISE: ss << "Player " << playerName << " raises with " << event.chips << "."; break;
case E_NEW_DEAL: ss << "New deal." << " Small Blind: " << event.smallBlind << " Big Blind: " << event.bigBlind << " Ante: " << event.ante; break;
case E_RECEIVE_CARDS: ss << "Received cards: " << event.card1.getShortName() << " " << event.card2.getShortName(); break;
case E_FLOP: ss << "Flop: " << event.card1.getShortName() << " " << event.card2.getShortName() << " " << event.card3.getShortName(); break;
case E_TURN: ss << "Turn: " << event.card4.getShortName(); break;
case E_RIVER: ss << "River: " << event.card5.getShortName(); break;
case E_SHOWDOWN: ss << "Showdown Reached"; break;
case E_POT_DIVISION: ss << "Betting finished. Pot size: " << event.chips; break;
case E_WIN: ss << "Player " << playerName << " wins " << event.chips; break;
case E_PLAYER_SHOWDOWN: ss << "Player " << playerName << " shows " << event.card1.getShortName() << " " << event.card2.getShortName(); break;
case E_BOAST: ss << "Player " << playerName << " boasts " << event.card1.getShortName() << " " << event.card2.getShortName(); break;
case E_COMBINATION:
{
Combination combo;
getCombo(combo, event.card1, event.card2, event.card3, event.card4, event.card5);
ss << "Player " << playerName << " has " << combo.getNameWithAllCards();
break;
}
case E_DEALER: ss << "Player " << playerName << " is dealer"; break;
case E_TOURNAMENT_RANK: ss << "Player " << playerName << " finishes at place " << event.position << ". Score: " << event.chips; break;
case E_REVEAL_AI: ss << "The AI of player " << playerName << " was: " << event.ai; break;
case E_LOG_MESSAGE: ss << event.message; break;
case E_DEBUG_MESSAGE: ss << "DEBUG MESSAGE: " << event.message; break;
default: ss << "??????";
}
return ss.str();
}
void sendEventToPlayers(std::vector<Player>& players, const Event& event)
{
for(size_t i = 0; i < players.size(); i++)
{
if(!players[i].isHuman() && (event.type == E_LOG_MESSAGE || event.type == E_DEBUG_MESSAGE)) continue; //AI's are not allowed to get this information.
players[i].onEvent(event);
}
}
void sendEventToObservers(std::vector<Observer*>& observers, const Event& event)
{
for(size_t i = 0; i < observers.size(); i++)
{
observers[i]->onEvent(event);
}
}
void sendEventsToPlayers(size_t& counter, std::vector<Player>& players, std::vector<Observer*>& observers, const std::vector<Event>& events)
{
for(size_t i = counter; i < events.size(); i++)
{
sendEventToPlayers(players, events[i]);
sendEventToObservers(observers, events[i]);
}
counter = events.size();
}