4 Copyright (c) 2010 Lode Vandevenne
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/>.
24 Linux compile command:
25 g++ *.cpp -W -Wall -Wextra -ansi -O3
26 g++ *.cpp -W -Wall -Wextra -ansi -g3
31 OOPoker, or "Object Oriented Poker", is a C++ No-Limit Texas Hold'm engine meant
32 to be used to implement poker AIs for entertainment or research purposes. These
33 AIs can be made to battle each other, or a single human can play against the AIs
34 for his/her enjoyment.
37 //In all functions below, when cards are sorted, it's always from high to low
45 #include "ai_blindlimp.h"
47 #include "ai_checkfold.h"
50 #include "ai_random.h"
53 #include "combination.h"
55 #include "host_terminal.h"
57 #include "io_terminal.h"
59 #include "observer_terminal.h"
60 #include "observer_terminal_quiet.h"
61 #include "observer_log.h"
62 #include "pokermath.h"
65 #include "tools_terminal.h"
71 std::cout
<< "Welcome to OOPoker\n\
72 Copyright (c) 2010-2014 Lode Vandevenne" << std::endl
<< std::endl
;
77 std::cout
<< "Choose Game Type\n\
79 2: human + AI heads-up\n\
81 4: AI battle heads-up\n\
82 r: random game (human)\n\
84 u: unit test" << std::endl
;
87 if(c
== '1') gameType
= 1;
88 else if(c
== '2') gameType
= 2;
89 else if(c
== '3') gameType
= 3;
90 else if(c
== '4') gameType
= 4;
91 else if(c
== 'r') gameType
= 5;
95 std::cout
<< "Choose Calculator\n\
97 2: Showdown" << std::endl
;
100 if(c2
== '1') runConsolePotEquityCalculator();
101 else runConsoleShowdownCalculator();
109 else if(c
== 'q') return;
117 rules
.allowRebuy
= false;
118 rules
.fixedNumberOfDeals
= 100;
120 std::cout
<< std::endl
<< std::endl
;
122 std::cout
<< "Choose Game Win Condition\n\
123 1: last remaining (no rebuys)\n\
124 2: rebuys, fixed 100 deals\n\
125 3: rebuys, fixed 1000 deals\n\
126 4: rebuys, fixed 10000 deals\n\
127 c: rebuys, fixed custom amount of deals" << std::endl
;
129 if(c
== '1') { rules
.allowRebuy
= false; rules
.fixedNumberOfDeals
= 0; }
130 else if(c
== '2') { rules
.allowRebuy
= true; rules
.fixedNumberOfDeals
= 100; }
131 else if(c
== '3') { rules
.allowRebuy
= true; rules
.fixedNumberOfDeals
= 1000; }
132 else if(c
== '4') { rules
.allowRebuy
= true; rules
.fixedNumberOfDeals
= 10000; }
137 std::cout
<< "enter number of deals: ";
140 rules
.allowRebuy
= true;
141 rules
.fixedNumberOfDeals
= strtoval
<int>(s
);
143 else if(c
== 'q') return;
145 std::cout
<< std::endl
<< std::endl
;
152 std::cout
<< "choose betting structure (buy-in, small, big)\n\
159 7: 100000, 50, 100\n\
160 8: 100000, 100, 200\n\
161 9: 1000, 5, 10, ante 1\n\
162 c: custom" << std::endl
;
164 if(c
== '1') {rules
.buyIn
= 1000; rules
.smallBlind
= 5; rules
.bigBlind
= 10; rules
.ante
= 0; }
165 else if(c
== '2') {rules
.buyIn
= 1000; rules
.smallBlind
= 10; rules
.bigBlind
= 20; rules
.ante
= 0; }
166 else if(c
== '3') {rules
.buyIn
= 1000; rules
.smallBlind
= 50; rules
.bigBlind
= 100; rules
.ante
= 0; }
167 else if(c
== '4') {rules
.buyIn
= 1000; rules
.smallBlind
= 100; rules
.bigBlind
= 200; rules
.ante
= 0; }
168 else if(c
== '5') {rules
.buyIn
= 100000; rules
.smallBlind
= 5; rules
.bigBlind
= 10; rules
.ante
= 0; }
169 else if(c
== '6') {rules
.buyIn
= 100000; rules
.smallBlind
= 10; rules
.bigBlind
= 20; rules
.ante
= 0; }
170 else if(c
== '7') {rules
.buyIn
= 100000; rules
.smallBlind
= 50; rules
.bigBlind
= 100; rules
.ante
= 0; }
171 else if(c
== '8') {rules
.buyIn
= 100000; rules
.smallBlind
= 100; rules
.bigBlind
= 200; rules
.ante
= 0; }
172 else if(c
== '9') {rules
.buyIn
= 1000; rules
.smallBlind
= 5; rules
.bigBlind
= 10; rules
.ante
= 1; }
177 std::cout
<< "enter buy-in amount: ";
179 rules
.buyIn
= strtoval
<int>(s
);
181 std::cout
<< "enter small blind: ";
183 rules
.smallBlind
= strtoval
<int>(s
);
185 std::cout
<< "enter big blind: ";
187 rules
.bigBlind
= strtoval
<int>(s
);
189 std::cout
<< "enter ante: ";
191 rules
.ante
= strtoval
<int>(s
);
194 else if(c
== 'q') return;
198 if(getRandom() < 0.2)
200 rules
.ante
= getRandom(1, 5);
202 rules
.bigBlind
= getRandom(10, 200);
203 //make nice round number
204 rules
.bigBlind
= getNearestRoundNumber(rules
.bigBlind
);
205 rules
.smallBlind
= rules
.bigBlind
/ 2;
207 rules
.buyIn
= getRandom(500, 200000);
208 rules
.buyIn
= getNearestRoundNumber(rules
.buyIn
);
211 game
.setRules(rules
);
213 std::vector
<Event
> events
;
215 std::vector
<Player
> players
;
216 std::vector
<Observer
*> observers
;
218 game
.addObserver(new ObserverLog("log.txt"));
220 if(gameType
== 1) //Human + AI's
222 game
.addPlayer(Player(new AIHuman(&host
), "You"));
224 //choose the AI players here
225 game
.addPlayer(Player(new AIRandom(), getRandomName()));
226 game
.addPlayer(Player(new AISmart(), getRandomName()));
227 game
.addPlayer(Player(new AISmart(), getRandomName()));
228 game
.addPlayer(Player(new AISmart(), getRandomName()));
229 game
.addPlayer(Player(new AISmart(), getRandomName()));
230 game
.addPlayer(Player(new AISmart(), getRandomName()));
231 game
.addPlayer(Player(new AISmart(), getRandomName()));
233 else if(gameType
== 2) //Human + AI heads-up
235 game
.addPlayer(Player(new AIHuman(&host
), "You"));
237 //choose the AI player here
238 game
.addPlayer(Player(new AISmart(), getRandomName()));
240 else if(gameType
== 3) //AI Battle
242 //game.addObserver(new ObserverTerminalQuiet());
243 game
.addObserver(new ObserverTerminal());
245 //choose the AI players here (AISmart, AIRandom, AICall, ...)
246 game
.addPlayer(Player(new AISmart(), getRandomName()));
247 game
.addPlayer(Player(new AISmart(), getRandomName()));
248 game
.addPlayer(Player(new AISmart(), getRandomName()));
249 game
.addPlayer(Player(new AISmart(), getRandomName()));
250 game
.addPlayer(Player(new AISmart(), getRandomName()));
251 game
.addPlayer(Player(new AISmart(), getRandomName()));
252 game
.addPlayer(Player(new AISmart(), getRandomName()));
253 game
.addPlayer(Player(new AISmart(), getRandomName()));
254 game
.addPlayer(Player(new AISmart(), getRandomName()));
255 game
.addPlayer(Player(new AISmart(), getRandomName()));
257 //for benchmarking game logic with only AICall bots
258 //game.addPlayer(Player(new AICall(), getRandomName()));
259 //game.addPlayer(Player(new AICall(), getRandomName()));
260 //game.addPlayer(Player(new AICall(), getRandomName()));
261 //game.addPlayer(Player(new AICall(), getRandomName()));
262 //game.addPlayer(Player(new AICall(), getRandomName()));
263 //game.addPlayer(Player(new AICall(), getRandomName()));
264 //game.addPlayer(Player(new AICall(), getRandomName()));
265 //game.addPlayer(Player(new AICall(), getRandomName()));
266 //game.addPlayer(Player(new AICall(), getRandomName()));
267 //game.addPlayer(Player(new AICall(), getRandomName()));
270 else if(gameType
== 4) //AI heads-up
272 game
.addObserver(new ObserverTerminalQuiet());
274 //choose two AI players here
275 game
.addPlayer(Player(new AIRandom(), getRandomName()));
276 game
.addPlayer(Player(new AISmart(), getRandomName()));
278 else if(gameType
== 5) //random game (human)
280 game
.addPlayer(Player(new AIHuman(&host
), "You"));
282 size_t num
= getRandom(1, 9);
283 for(size_t i
= 0; i
< num
; i
++)
285 game
.addPlayer(Player(getRandom() < 0.1 ? (AI
*)(new AIRandom()) : (AI
*)(new AISmart()), getRandomName()));
298 pressAnyKey(); //prevent closing terminal window.