update readme
[rofl0r-oopoker.git] / action.cpp
blob89e9f2330f048014bcb7bf856d17f796c1b41fc6
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 #include "action.h"
24 #include "info.h"
26 Action::Action(Command command, int amount)
27 : command(command)
28 , amount(amount)
32 Action::Action()
33 : command(A_FOLD)
34 , amount(0)
39 bool isValidAllInAction(const Action& action, int stack, int wager, int highestWager, int highestRaise)
41 (void)highestRaise;
43 int callAmount = highestWager - wager;
45 switch(action.command)
47 case A_FOLD:
49 return false;
51 case A_CHECK:
53 return false;
55 case A_CALL:
57 return callAmount >= stack;
59 case A_RAISE:
61 return action.amount > 0 && action.amount == stack; //must be exact. If higher, it's an invalid action.
62 break;
64 default: return false;
68 bool isValidAction(const Action& action, int stack, int wager, int highestWager, int highestRaise)
70 int callAmount = highestWager - wager;
72 switch(action.command)
74 case A_FOLD:
76 return true;
78 case A_CHECK:
80 return callAmount == 0;
82 case A_CALL:
84 if(callAmount == 0) return false; //you should use check in this case. Otherwise player statistics get messed up. So, disallowed!
85 return stack > 0; //it's always valid for the rest, as long as your stack isn't empty. If call amount is bigger than your stack, you go all-in, it's still a valid call.
87 case A_RAISE:
89 int raiseAmount = action.amount - callAmount;
90 return (action.amount <= stack && raiseAmount >= highestRaise)
91 || isValidAllInAction(action, stack, wager, highestWager, highestRaise);
92 break;
96 return false;