fix infinite check bug
[rofl0r-oopoker.git] / statistics.h
blobc842d9ac4305c85ad2639290bb257d2e5716817f
1 /*
2 OOPoker
4 Copyright (c) 2010 Lode Vandevenne
5 All rights reserved.
7 This file is part of OOPoker.
9 OOPoker is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 OOPoker is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with OOPoker. If not, see <http://www.gnu.org/licenses/>.
23 #pragma once
25 #include "event.h"
26 #include "game.h"
28 #include <map>
29 #include <string>
31 //WARNING: all percentages are given as values in range 0.0-1.0, NOT values in range 0-100! So 1.0 means 100%.
33 struct PlayerStats
35 PlayerStats(const std::string& name);
37 std::string name;
38 std::string ai;
40 int deals; //how many deals (hands) this player played
41 int actions; //how many turns this player actively played (this is about it being the player's turn to make a decision, NOT about the turn that comes after the flop. See turns_seen for that)
43 //number of actions this player did divided per round
44 int preflop_actions;
45 int flop_actions;
46 int turn_actions;
47 int river_actions;
49 int chips_won; //number of chips gotten from the pot. This includes chips you had put yourself in the pot.
50 int chips_lost; //number of chips put on the table. Chips won back are also included here! Anything you bet, even if you get it back, is considered lost here.
51 int chips_bought; //how much buy-in
52 int forced_bets; //how much paid in blinds and antes
54 int flops_seen; //how many times this player actively reached the flop
55 int turns_seen; //how many times this player actively reached the turn
56 int rivers_seen; //how many times this player actively reached the river
57 int showdowns_seen; //This should normally be equal to "deals - folds".
59 int wins_total; //how many times this player won (part of) the pot (includes ties)
60 int wins_showdown; //how many times this player won at showdown
61 int wins_bluff; //how many times this player won without showdown (not necessarily bluff, but I just call winning without showdown "bluff" here for convenience)
65 All the actions below are the total amount of actions of the player. There can be more actions than rounds. So the
66 values below are not useful for some statistics, such as VP$IP, that are defined per deal. There are other values for
67 that further on.
69 The sum of folds, checks, calls, bets and raises is exactly equal to the value "actions".
70 allins is on top of that, because an allin is also counted as call, bet or raise.
73 int folds; //number of times this player folded
74 int checks; //number of times this player checked
75 int calls; //number of times this player called, includes some all-ins.
76 int bets; //number of times this player bet includes some all-ins. (NOTE: in OOPoker "bet" and "raise" are often both called "raise", but in the statistics the difference is made!!)
77 int raises; //number of times this player raised, includes some all-ins. (NOTE: in OOPoker "bet" and "raise" are often both called "raise", but in the statistics the difference is made!!)
78 int allins; //number of times this player went all-in (both if it happened by calling, raising, or blinds)
81 The stats below are divided per round. But, beware, since there can be multiple actions per round, they can
82 occur multiple times per round. The deal_preflop_### stats further on are more useful for some defined statistics.
85 //The sum of preflop_folds, preflop_checks, preflop_calls, preflop_bets and preflop_raises is exactly equal to the value "preflop_actions". (allins comes on top of that, they're counted as call, bet or raise already)
86 int preflop_folds;
87 int preflop_checks;
88 int preflop_calls;
89 int preflop_bets;
90 int preflop_raises;
91 int preflop_allins;
93 //The sum of flop_folds, flop_checks, flop_calls, flop_bets and flop_raises is exactly equal to the value "flop_actions". (allins comes on top of that, they're counted as call, bet or raise already)
94 int flop_folds;
95 int flop_checks;
96 int flop_calls;
97 int flop_bets;
98 int flop_raises;
99 int flop_allins;
101 //The sum of turn_folds, turn_checks, turn_calls, turn_bets and turn_raises is exactly equal to the value "turn_actions". (allins comes on top of that, they're counted as call, bet or raise already)
102 int turn_folds;
103 int turn_checks;
104 int turn_calls;
105 int turn_bets;
106 int turn_raises;
107 int turn_allins;
109 //The sum of river_folds, river_checks, river_calls, river_bets and river_raises is exactly equal to the value "river_actions". (allins comes on top of that, they're counted as call, bet or raise already)
110 int river_folds;
111 int river_checks;
112 int river_calls;
113 int river_bets;
114 int river_raises;
115 int river_allins;
118 The per-deal stats. The preflop, flop, etc... stats can occur more than the number of rounds because it can take multiple turns to settle a betting round.
119 The stats below are kept ONCE per complete deal (the 4 rounds together). Also, each next stat overrides the previous one.
120 So the sum of these 5 values together, is exactly the number of deals the player played.
121 The override order is: raise > bet > call > check > first_action_fold
122 allin and fold after first action aren't included here, because those already happen once per deal anyway and thus can be deduced from the above stats.
124 E.G. If a player called pre-flop, but raised after the flop, only "deal_raises" will be increased.
126 int deal_first_action_folds; //folded at first action (folding after already having checked, called, ... isn't counted here, the other stats already tell that)
127 int deal_checks;
128 int deal_calls;
129 int deal_bets;
130 int deal_raises;
133 Similar to the deal stats above, but only for the pre-flop section of the game
134 The sum of deal_preflop_calls, deal_preflop_bets and deal_preflop_raises, divided through the total amount of deals, gives the voluntary put money in pot statistic of this player.
135 The sum of deal_preflop_first_action_folds and deal_preflop_checks gives the amount of deals in which the player did NOT voluntary put money in the pot.
137 The sum of deal_preflop_first_action_folds, deal_preflop_checks, deal_preflop_calls, deal_preflop_bets and deal_preflop_raises is exactly equal to the amount of deals the player played.
139 int deal_preflop_first_action_folds; //folded at first action (folding after already having checked, called, ... isn't counted here, the other stats already tell that)
140 int deal_preflop_checks;
141 int deal_preflop_calls;
142 int deal_preflop_bets;
143 int deal_preflop_raises; //this are the RE-raises before the flop, a.k.a. the 3bets (or 4bets or higher)
145 //todo: add action statistics per position: sb, bb, early, mid, late
147 //todo: add statistics about starting hands of player (connecters, pocket pairs, ...) if that info is known.
149 //todo: add statistics about the amount of players at the table during the actions, wins, ...
151 //Pre-Flop statistics deduced from the above values
152 double getVPIP () const; //Voluntary Put Money In Pot: returned as value in range 0.0-1.0. Number of times player voluntarily called or raised at least once during a deal.
153 double getPFR() const; //Pre-Flop Raise percentage: returned as value in range 0.0-1.0.
154 double get3BetPF() const; //number of times this player reraised pre-flop (as value 0.0-1.0)
156 //Post-Flop statistics deduced from the above values
157 double getWSD() const; //Went To ShowDown: showdowns seen percentage (as value 0.0-1.0)
158 double getWSDW() const; //Went To ShowDown and Won (percentages of showdowns won): as percentage (as value 0.0-1.0)
159 double getAF() const; //Aggression Factor. Larger means more aggressive, smaller means more passive. Measured only after the flop.
162 struct TableStats
164 TableStats();
166 int deals;
167 int flops_seen;
168 int turns_seen;
169 int rivers_seen;
171 int joins; //amount of players joining
172 int quits; //amount of players quitting
174 //todo: stats about the playing style at this table
177 class StatKeeper
179 protected:
181 struct MyPlayerInfo
183 MyPlayerInfo(const std::string& player);
185 PlayerStats stats;
186 int stack; //stack kept track of through events
187 int wager; //wager kept track of through events (bet = how much player moved in pot during this deal)
188 bool joined; //false if the player quits
189 bool folded; //folded during this deal
190 int deal_stat; //0: first action fold / uninited, 1: check, 2: call, 3: bet, 4: raise. Used for tracking the "deal_###" stats.
191 int deal_preflop_stat; //0: first action fold / uninited, 1: check, 2: call, 3: bet, 4: raise. Used for tracking the "deal_preflop_###" stats.
194 std::map<std::string, MyPlayerInfo*> statmap;
196 MyPlayerInfo* getPlayerStatsInternal(const std::string& player); //this adds it to the std::map if needed
197 TableStats tableStats;
199 Round round; //round deduced from the events
201 int highestBet; //kept track from from the events, to calculate callamount for current player from
203 public:
205 StatKeeper();
206 ~StatKeeper();
208 void onEvent(const Event& event);
210 const PlayerStats* getPlayerStats(const std::string& player) const; //returns null if no stats for that player are available
211 const TableStats* getTableStats() const;
212 void getAllPlayers(std::vector<std::string>& players) const;
215 std::string statisticsToString(const PlayerStats& stats);
216 std::string statisticsToString(const StatKeeper& statKeeper);