update readme
[rofl0r-oopoker.git] / main.cpp
blob989d077e344c04a5bc8aca4011a753ea356d9a7d
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/>.
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
39 #include <vector>
40 #include <string>
41 #include <algorithm>
42 #include <iostream>
44 #include "ai.h"
45 #include "ai_blindlimp.h"
46 #include "ai_call.h"
47 #include "ai_checkfold.h"
48 #include "ai_human.h"
49 #include "ai_raise.h"
50 #include "ai_random.h"
51 #include "ai_smart.h"
52 #include "card.h"
53 #include "combination.h"
54 #include "game.h"
55 #include "host_terminal.h"
56 #include "info.h"
57 #include "io_terminal.h"
58 #include "observer.h"
59 #include "observer_terminal.h"
60 #include "observer_terminal_quiet.h"
61 #include "observer_log.h"
62 #include "pokermath.h"
63 #include "random.h"
64 #include "table.h"
65 #include "tools_terminal.h"
66 #include "unittest.h"
67 #include "util.h"
69 void doGame()
71 std::cout << "Welcome to OOPoker\n\
72 Copyright (c) 2010-2014 Lode Vandevenne" << std::endl << std::endl;
74 char c = 0;
77 std::cout << "Choose Game Type\n\
78 1: human + AI's\n\
79 2: human + AI heads-up\n\
80 3: AI battle\n\
81 4: AI battle heads-up\n\
82 r: random game (human)\n\
83 c: calculator\n\
84 u: unit test" << std::endl;
85 c = getChar();
86 int gameType = 1;
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;
92 else if(c == 'c')
95 std::cout << "Choose Calculator\n\
96 1: Pot Equity\n\
97 2: Showdown" << std::endl;
99 char c2 = getChar();
100 if(c2 == '1') runConsolePotEquityCalculator();
101 else runConsoleShowdownCalculator();
102 return;
104 else if(c == 'u')
106 doUnitTest();
107 return;
109 else if(c == 'q') return;
113 Rules rules;
114 rules.buyIn = 1000;
115 rules.bigBlind = 10;
116 rules.ante = 0;
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;
128 c = getChar();
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; }
133 else if(c == 'c')
135 std::string s;
137 std::cout << "enter number of deals: ";
138 s = getLine();
140 rules.allowRebuy = true;
141 rules.fixedNumberOfDeals = strtoval<int>(s);
143 else if(c == 'q') return;
145 std::cout << std::endl << std::endl;
147 HostTerminal host;
148 Game game(&host);
150 if(gameType != 5)
152 std::cout << "choose betting structure (buy-in, small, big)\n\
153 1: 1000, 5, 10\n\
154 2: 1000, 10, 20\n\
155 3: 1000, 50, 100\n\
156 4: 1000, 100, 200\n\
157 5: 100000, 5, 10\n\
158 6: 100000, 10, 20\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;
163 c = getChar();
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; }
173 else if(c == 'c')
175 std::string s;
177 std::cout << "enter buy-in amount: ";
178 s = getLine();
179 rules.buyIn = strtoval<int>(s);
181 std::cout << "enter small blind: ";
182 s = getLine();
183 rules.smallBlind = strtoval<int>(s);
185 std::cout << "enter big blind: ";
186 s = getLine();
187 rules.bigBlind = strtoval<int>(s);
189 std::cout << "enter ante: ";
190 s = getLine();
191 rules.ante = strtoval<int>(s);
194 else if(c == 'q') return;
196 else
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()));
289 game.doGame();
293 int main()
295 doGame();
298 pressAnyKey(); //prevent closing terminal window.
300 return 0;