fix infinite check bug
[rofl0r-oopoker.git] / info.h
blob10027175e601facb0ef83b860079fab27bfab816
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 "rules.h"
26 #include "event.h"
28 struct Action;
31 Info has the same information as Table, but only the information that is visible
32 for a certain player, and presented such that modifying it doesn't cause harm to
33 the game itself, since it's only a copy of the information.
35 It also contains various utility methods.
37 This is the Info an AI gets for each decision.
39 pokermath.h
40 card.h
41 combination.h
42 random.h
44 All other header files are probably less useful for an AI (they're for running the game)
47 #include "action.h"
48 #include "rules.h"
50 //info about a player for a turn during the betting
51 struct PlayerInfo
53 bool folded; //if true, this player has already folded for this game. Either just now (if his action has FOLD in it), or earlier (if his action has ACTION_NONE in it).
55 std::string name; //name of the player
56 int stack;
57 int wager; //how much money this player has bet during the whole game so far (where game is one hand)
59 Action lastAction; //what the player did this turn (most recent action of this player)
61 bool showdown; //if true, the hand card values of this player are stored in the holeCard variables.
62 std::vector<Card> holeCards;
64 PlayerInfo();
66 const std::string& getName() const;
68 bool isAllIn() const;
69 bool isOut() const; //can't play anymore, has no more money
70 bool isFolded() const;
71 bool canDecide() const; //returns true if stack > 0 and not folded
74 struct Info //all the info a player gets during a decision
76 ///Personal Info
78 int yourIndex; //your index in the players vector of the table, or -1 if this info is global. This is not your position. Use getPosition to get your position compared to the dealer.
80 ///Global Info
82 int dealer; //index of the dealer
83 int current; //index of the player currently making a decision
85 Round round;
86 int turn; //the number of times you had to decide for this Round (where Round is pre-flop, flop, etc...). Normally this is 1. If someone raised causing the betting to go round again, this increases. So this is kind of a "sub-round" index in fact
88 int minRaiseAmount; //minimum raise amount *above the call amount* to be able to raise according to the game rules
90 //NOTE: the values of these cards are only valid if the Round is correct.
91 std::vector<Card> boardCards; //the community cards on the table. 0 pre-flop, 3 at flop, 4 at turn, 5 at river.
93 std::vector<PlayerInfo> players; //you yourself are included in this vector, at yourIndex
95 Rules rules;
97 ///Constructor
99 Info();
101 bool isGlobal() const; //if this returns true, then this Info is NOT about you as player, but contains only the globally known information. If this returns true, do NOT use any of the functions that involve you (such as getMRatio(), getSmallBlind(), ...)
103 ///Personal Utility methods. Only use if isGlobal() returns false.
105 const PlayerInfo& getYou() const;
107 const std::vector<Card>& getHoleCards() const; //shortcut to your hole cards
109 int getCallAmount() const; //get amount of money required for you to call
110 int getMinChipsToRaise() const; //get amount of chips you need to move to the table to raise with the minimum raise amount. This is getCallAmount() + lastRaiseAmount
112 int getPosition() const; //returns 0 if you're dealer, 1 for sb, 2 for bb, 3 = under the gun, getNumPlayers()-1 = cut-off.
114 int getStack() const; //get your stack
115 int getWager() const; //get your wager
117 //For more statistics like this, see pokermath.h
118 double getMRatio() const; //returns (your stack) / (small blind + big blind + total antes), in other words, the number of laps you can still survive with your current stack
119 double getPotOdds() const; //this gives getPot() / getCallAmount(). Can be infinite if callamount is 0. Higher is better.
120 double getPotOddsPercentage() const; //gets pot odds as a percengate. Gives callAmount / (total pot + callAmount). For example if the pot odds are 2:1, then the percentage is 33.3% (and the return value is 0.33 since it's a number in the range 0.0-1.0)
121 double getPotEquity() const; //see description in pokermath.h for more information about this function. This here is just a convenience wrapper.
123 //get std::vectors of cards, handy for calling some of the mathematical functions
124 std::vector<Card> getHandTableVector() const;
127 Is the action allowed by the game?
128 It is not allowed if:
129 -you need to move more chips to the table than you have in your stack to perform this action (unless you go all-in)
130 -it's a raise action but the amount of chips raised is smaller than the highest raise so far this deal (unless you go all-in)
131 -it's a check action while the call amount is higher than 0
133 bool isValidAction(const Action& action) const;
134 bool isValidAllInAction(const Action& action) const; //will this action bring you all-in? This function must be called before the action is performed (after it's performed your stack is 0 and then the checks in this function don't work anymore)
136 Action getCheckFoldAction() const; //checks if possible, folds otherwise
137 Action amountToAction(int amount) const; //converts a number (representing stack amount you offer), to an action. If the number is greater than your stack, it'll make it an all-in action the size of your stack instead. The returned action will be a valid action, no matter what amount given. If the amount has to be changed, it'll always be smaller, not bigger, than the given amount.
138 Action getCallAction() const; //returns call action if call amount > 0, check action otherwise
139 Action getRaiseAction(int raise) const; //calls amountToAction with getCallAmount() added
140 Action getAllInAction() const; //creates action of type call or raise depending on your stack size and call amount, so that you're all-in
143 ///Global versions of the per-player utility methods. Allows giving player index.
145 const std::vector<Card>& getHoleCards(int index) const; //shortcut to your hole cards
147 int getCallAmount(int index) const; //get amount of money required for you to call
148 int getMinChipsToRaise(int index) const; //get amount of chips you need to move to the table to raise with the minimum raise amount. This is getCallAmount() + lastRaiseAmount
150 int getPosition(int index) const; //returns 0 if you're dealer, 1 for sb, 2 for bb, 3 = under the gun, getNumPlayers()-1 = cut-off.
152 int getStack(int index) const; //get your stack
153 int getWager(int index) const; //get your wager
155 //For more statistics like this, see pokermath.h
156 double getMRatio(int index) const; //returns (your stack) / (small blind + big blind + total antes), in other words, the number of laps you can still survive with your current stack
157 double getPotOdds(int index) const; //this gives getPot() / getCallAmount(). Can be infinite if callamount is 0. Higher is better.
158 double getPotOddsPercentage(int index) const; //gets pot odds as a percengate. Gives callAmount / (total pot + callAmount). For example if the pot odds are 2:1, then the percentage is 33.3% (and the return value is 0.33 since it's a number in the range 0.0-1.0)
159 double getPotEquity(int index) const; //see description in pokermath.h for more information about this function. This here is just a convenience wrapper.
161 ///Global Utility methods. Can always be used.
163 int wrap(int index) const; //wrap: convert any index into a valid player index. For example if you do "yourIndex - 1", this gets converted to the index of the player left of you, even if yourIndex was 0
165 int getPot() const; //sum of all players bets
166 int getHighestWager() const; //highest amount of money put on the table by a player (including yourself). The call-amount can be calculated from this.
168 int getNumPlayers() const; //amount of players at the table
170 int getNumActivePlayers() const; //players that are not folded or out
171 int getNumDecidingPlayers() const; //get amount of players that can still make decisions. All-in, folded or out players cannot.
173 int getSmallBlind() const;
174 int getBigBlind() const;
178 //TODO: generate info from events
179 //class InfoKeeper
181 //private:
182 //Info info;
184 //public:
186 //const Info& getInfo() const;
188 //InfoKeeper(int yourIndex); //set to -1 for global-only info
189 //~InfoKeeper();
191 //void onEvent(const Event& event);
192 //};