fix infinite check bug
[rofl0r-oopoker.git] / readme.txt
blob68cf175b4efdb80dbcd36c6cbd68c24e82b90f74
1 OOPoker
2 -------
4 .------..------..------..------..------..------..------.
5 |O.--. ||O.--. ||P.--. ||O.--. ||K.--. ||E.--. ||R.--. |
6 | :/\: || :/\: || :/\: || :/\: || :/\: || (\/) || :(): |
7 | :\/: || :\/: || (__) || :\/: || :\/: || :\/: || ()() |
8 | '--'O|| '--'O|| '--'P|| '--'O|| '--'K|| '--'E|| '--'R|
9 `------'`------'`------'`------'`------'`------'`------'
12 Table of Contents:\r
14 0 Introduction\r
15 1 Terminology\r
16 2 Using the program\r
17   2.1 System Requirements\r
18   2.2 Gameplay\r
19   2.3 Battling AIs\r
20   2.4 Player Statistics\r
21 3 Programming AIs\r
22   3.1 Really Quickly Getting Started\r
23   3.2 C++, Compiler and IDE.\r
24     3.2.1 C++\r
25     3.2.2 Compiler\r
26     3.2.3 Language\r
27   3.3 Implementing the AI\r
28   3.4 Putting your AI in the game\r
29   3.5 Utility Functions\r
30   3.6 Fast Evaluation (For Win Equity)\r
31   3.7 OOPoker Code Overview\r
32   3.8 Making a Graphical or Webserver Interface\r
33 4 Texas Hold'm Rules\r
34 5 Contact Information\r
36 ////////////////////////////////////////////////////////////////////////////////
37 ////////////////////////////////////////////////////////////////////////////////
38 ////////////////////////////////////////////////////////////////////////////////
39 ////////////////////////////////////////////////////////////////////////////////
41 Chapter 0: Introduction
42 -----------------------
45 OOPoker, or "Object Oriented Poker", is a C++ No-Limit Texas Hold'm engine meant
46 to be used to implement poker AIs for entertainment  or research purposes. These
47 AIs can be made to battle each other, or a single human can play against the AIs
48 for his/her enjoyment.
50 OOPoker is completely open source, it is licensed under GPL 3. It is hosted
51 here: https://github.com/lvandeve/oopoker
53 Currently only open source C++ code AIs are supported, it doesn't support play
54 over network or through encapsulated protocols at this time.\r
56 This program is intended mostly to be used by people who like programming, but
57 it's also possible to enjoy the program without programming by just running\r
58 it and playing against the built-in AIs.
60 This manual will explain two things:
62 -how to use the program to play
63 -how to program and use your own AIs
65 ////////////////////////////////////////////////////////////////////////////////
66 ////////////////////////////////////////////////////////////////////////////////
67 ////////////////////////////////////////////////////////////////////////////////
68 ////////////////////////////////////////////////////////////////////////////////
71 Chapter 1: Terminology
72 ----------------------
74 This chapter explains the terminology used both in the game and in the source
75 code.
77 Some terms can have multiple confusing meanings in Poker, especially "game", "hand", "bet" and "turn". For
78 that reason, some things are named differently here when possible, to avoid confusion.
80 Basically, a game of OOPoker is structured like this:
82 *) A Game = a complete tournament at 1 table. A game exists out of multiple Deals.
83 *) A Deal = dealing the cards. A Deal exists out of multiple Rounds.
84 *) A Round = pre-flop, flop, turn or river. A Round exists out of multiple Turns.
85 *) A Turn = one time going around the table while settling bets. Multiple turns occur if players keep raising. A Turn exists out of multipe Decisions.
86 *) A Decision = an action, one player making a decision during his turn.
88 Here's the full terminlogy list (alphabetically):
90 *) Action: choice a player can make: fold, check, call or raise.
92 *) All-in: action where you put so many chips on the table that your stack becomes empty. Sometimes
93    this is forced (e.g. when the blind was bigger than your stack).
95 *) Bet: an action where you raise when the call amount was 0. In OOPoker, usually the term
96    raise is used for the action that is normally called "bet" in poker, because mechanically,
97    "bet" and "raise" have the same effect. For example there's an action "A_RAISE" and an event "E_RAISE"
98    that take the role of both bet and raise.
99    If you need to distinguish bet and raise, keep track of the current call amount,
100    when it's 0, it's a bet instead of a raise.
101    However, in the PlayerStats statistics, "bets" and "raises" are separated.
102    To avoid confusion, amounts of chips aren't called "bet", but "wager" instead.
104 *) Betting Structure: information about the blinds, antes and buy-in amount at this table.
106 *) Big blind: the chip amount the big blind is, and, the player who is  big blind during this deal.
108 *) Boast: This isn't a real poker term, but this term is used in OOPoker to indicate
109    you show your cards at the end of a deal when it wasn't required. So this is the opposite of "muck".
111 *) Call: action where you move the minimum required chips to not fold on the table.
113 *) Call Amount: amount of money you need to move from your stack to the table to call. This is the highest
114    wager on the table minus your current wager.
116 *) Check: action where you don't have to call and don't raise.
118 *) Chips: the money, or poker chips, played with.
120 *) Combination: a 5-card combination, that can form such a combination as full-house, pair, ...
121    A combination can be formed from 7 cards in Texas Hold'm, in that case the best possible
122    5-card combination is taken.
123    Also, the mathematical combination or binomial coefficient operation.
125 *) Deal: a single deal of cards and all that comes after it (flop, turn, river, showdown, if
126    the game doesn't end before that at least).
128 *) Dealer: the player who is dealer (or "the button") during this deal.
130 *) Decision: a player deciding what Action to do during his turn. Sometimes this is also just called "action", e.g. in the Statistics.
132 *) Deck: a complete deck of 52 cards.
134 *) Flop: the second round, when 3 cards are visible on the table.
136 *) Fold: action where you stop betting for this deal. You can't win the pot anymore.
138 *) Game: the term "game" refers to the game of poker in general, or this computer game, or the running
139    of the gameplay with Texas Hold'm rules. A game NEVER means a "deal" here, to avoid confusion.
140    A game can mean a complete tournament or a series of deals however.
142 *) Hand: the two cards you have in your hand
144 *) Hand card: a card you have in your hand
146 *) Lap: a lap of the dealer button, e.g. if there are 9 players this is 9 deals
148 *) Player: one person or AI playing.
150 *) Pot: the total amount of chips on the table during this deal so far. This is the sum of the bet of all players.
152 *) Stack: the amount of chips a certain player has.
154 *) Table: a table with a certain amount of players around it, who are playing poker.
156 *) Table card: card from the flop, turn or river on the table. Also called the board, or community cards.
158 *) turn (no caps): A turn of the players. In a turn, each player can choose to fold, raise, etc...
159    During a betting round, there can be multiple turns if players keep raising. Not to be confused with "TURN"!
161 *) TURN (caps): The Turn, that is, the 3rd round, when the 4th card on the table
162    becomes visible. Not to be confused with "turn"!
164 *) Round: AKA "betting round". There are maximum 4 betting rounds in a Deal: pre-flop,
165    flop, turn and river.
167 *) Pre-Flop: the first round, before any cards on the table are visible.
169 *) Pot: the sum of all wagers on the table.
171 *) Raise: action where the player bets extra money over the required call amount. The distinction
172    between "betting" and "raising" isn't really made in OOPoker, it's always called "raise".
174 *) Raise Amount: This terminology isn't from real poker, only relevant in OOPOker. It's the amount of
175    chips placed on top of the Call Amount, to raise. So basically in regular poker this is just
176    "the raise", but in OOPoker sometimes care must be taken if an amount of chips means the raise
177    amount above the call amount, or the total amount of chips you move to the table.
179 *) River: the 4th and last round, when the 5th card on the table becomes visible.
181 *) Showdown: when multiple players are still not folded after the river, they show
182    their cards to determine the winner with the best combination. The showdown stage
183    occurs after the river, only if multiple players are still active.
185 *) Small blind: the chip amount the small blind is, and, the player who is small blind during this deal.
187 *) Wager: The amount of chips that a player moved to the table (in the pot) during this deal so far. The
188    sum of all wagers, is the pot.
190 ////////////////////////////////////////////////////////////////////////////////
191 ////////////////////////////////////////////////////////////////////////////////
192 ////////////////////////////////////////////////////////////////////////////////
193 ////////////////////////////////////////////////////////////////////////////////
196 Chapter 2: Using the program
197 ----------------------------
199 2.1 System Requirements\r
200 -----------------------\r
202 *) Works on most computers, no special graphics hardware or fastest processor is needed\r
203 *) Operating System: Windows or Linux\r
204 *) Free disk space when using the logger (it's enabled by default). When emulating
205    10000's of games, the log file tends to become quite big.\r
209 2.2 Gameplay\r
210 ------------
212 The program currently works in a terminal window. When the program starts, a few
213 choices appear about the game type, the size of the buy-in, blinds, etc...
215 The game type choices are as follows:
217 *) human + AI's: play as human against multiple AI opponents
218 *) human + AI heads-up: play as human against a single AI opponent
219 *) AI battle: multiple AI's will play, at the end a winner will be declared. The human being can observe.
220 *) AI battle heads-up: two AI's will play against each other, at the end a winner will be declared. The human being can observe.
222 Next, you can choose a win condition, either the last
223 surviver at the table wins, or players can rebuy and there is a fixed amount of turns.\r
225 Due to the way the terminal input is programmed for this menu, you can hit keystrokes in a row to quickly\r
226 start a certain type of game. E.g. if you hit "3 2 1" in a row, an AI battle with 100 fixed rounds and\r
227 stacks of 1000 chips will start.\r
229 When you play as human, when it is your turn to make a decision, you simply have to
230 enter an amount of chips you move to the table. Depending on how much chips you move,
231 your action will be fold, check, call, bet/raise or all-in.
233 You don't have to explicetely choose "fold" or "check". Instead, for example when
234 the amount required to call is 50 chips, then when you'd enter 0, you'd fold,
235 when you'd enter 50, you'd call, and when you'd enter 200, you'd raise with 150.
237 While the game is running, at any time, you can press the "q" key, and it'll immediatly\r
238 stop (no confirmation is asked!!).\r
240 Sometimes you can enter "o" for an options menu. The options menu allows choosing\r
241 a delay between AI opponents. The delay allows following the game better, if there's\r
242 no delay, most AIs make a decision immediatly.
244 While playing, you see all events that happen, and whenever you can make a decision,
245 you see an ASCII-art representation of the table. Here's an example of a game in session
246 in the terminal:
248   > Player You calls.
249   > Player Laboes folds.
250   > Player Pimuve folds.
251   > Flop: 4c 6h Jh
252   > Player Heevapoe checks.
253   > Player Reeloehitry raises with 200.
254   > Player Faweel folds.
255                                                folded
256                   Heevapoe     Reeloehitry     Faweel
257                     $7600         $7400         $7600
258                     ##################################
259                   ### $2400      $2600        $2400  ###
260      folded      ##                                    ##    folded
261       Vonhi     ##                                      ##     Poero
262       $10000    ##             O O P O K E R            ##     $10000
263                 ##            4c 6h Jh .. ..            ##
264    folded (B)   ##                                      ##
265      Pimuve     ##  $200                                ##
266       $9800      ##               Qc Kh                ##
267                   ###   $100      $2400              ###
268                     ##################################
269                    Laboes          You
270                     $9900         $7600
271                  folded (S)    Current (D)
272   chip amount (200 to call, q to quit, o for options):
275 At any time during the game, even if the program isn't awaiting terminal input,\r
276 you can hit the "q" key to immediatly stop the game.\r
278 2.3 Battling AIs\r
279 ----------------\r
281 You can make AIs play against each other without human involvement. This is called\r
282 an "AI Battle". You can test how good or bad your AI's are compared to other AI's by\r
283 making them play against each other this way.\r
285 There are different ways to score the AIs: either the last survivor wins (and no\r
286 rebuys are allowed), or rebuys are allowed and the AI who won the most money after\r
287 a fixed amount of turns wins. The larger you set this fixed amount of turns, the\r
288 more precise you can determinate which AI is the smartest (but it takes a longer\r
289 time to run).\r
291 At the end you can see which AIs won, and their statistics.\r
293 2.4 Player Statistics\r
294 ---------------------\r
296 At the end of a game, you might see some player statistics like this:\r
298 Player Stats for Nekana, AI: Smart\r
299 General: deals: 1000 actions: 1822 preflop actions: 1172\r
300 Rounds Seen: flops: 247 turns: 206 rivers: 170 showdowns: 140\r
301 Wins: total: 93 showdown: 72 bluff: 21\r
302 Chips: won: 148221 lost: 199272 bought: 7000 forced bets: 1500\r
303 Pre-Flop Stats: VP$IP: 0.306 PFR: 0.083 3Bet: 0.081\r
304 Post-Flop Stats: AF: 1.41667 WSD: 0.14 WSDW: 0.072\r
306 The meaning of some of the values are:\r
308 *Pre-Flop*\r
310 VP$IP, VPIP: Percentage: Voluntary Put Money In Pot:\r
311   Tight: Less than 0.24\r
312   Neutral: Between 0.24-0.3\r
313   Loose: Greater than 0.3\r
315 PFR: Pre-Flop Raise percentage: percentage of bets or raises before the flop, percentage given in range 0.0-1.0\r
316   Passive: less than 1/4th of VPIP\r
317   Agressive: more than 1/4th of VPIP\r
319 Pre-Flop 3Bet percentage: percentage of reraises before the flop, percentage given in range 0.0-1.0\r
321 *Post-Flop*\r
323 AF: Aggression Factor after the flop:\r
324   Passive: Less than 1.5\r
325   Neutral: Between 1-1.5\r
326   Aggressive: Greater than 1.5\r
328 WSD: Went to ShowDown percentage, percentage given in range 0.0-1.0 (calculated as showdowns_seen / flops_seen)\r
329   Solid: less than 0.39 (A value of good players is 0.25)\r
330   Overplaying cards: Greater than 0.39\r
332 WSDW: Went to ShowDown and Won, percentage given in range 0.0-1.0\r
333   This is the amount of showdowns won (including split pots) divided through the total amount of showdowns seen.\r
335 ////////////////////////////////////////////////////////////////////////////////
336 ////////////////////////////////////////////////////////////////////////////////
337 ////////////////////////////////////////////////////////////////////////////////
338 ////////////////////////////////////////////////////////////////////////////////
341 Chapter 3: Programming AIs
342 --------------------------
344 This chapter will explain how to program your own OOPoker AIs, in C++.\r
346 Depending on your knowledge, you may be able to skip certain sections.
348 ////////////////////////////////////////////////////////////////////////////////
349 ////////////////////////////////////////////////////////////////////////////////
350 ////////////////////////////////////////////////////////////////////////////////
351 ////////////////////////////////////////////////////////////////////////////////\r
353 Section 3.1: Really Quickly Getting Started\r
354 -------------------------------------------\r
356 How to get the game working and have your own AI in it:\r
358 *) Get a C++ compiler and IDE.
359      Try Code::Blocks (http://www.codeblocks.org/), or see next sections.
360      Get the version WITH Mingw compiler included!\r
361 *) Set up your C++ project with the OOPoker source files, set the right project settings
362      With Code::Blocks, just open the file OOPoker.cbp, it should have all project settings ready.\r
363 *) Compile and run OOPoker, try out the game.
364      With Code::blocks, press F9 and it should compile and run the project.\r
365 *) Now to program your own AI:\r
366 *) Copy the files "ai_smart.cpp" and "ai_smart.h", and name your copies "ai_my_bot.cpp"\r
367 and "ai_my_bot.h".\r
368 *) Include these files in your C++ project.\r
369 *) In both files, rename all instances of "AISmart" to "AIMyBot".\r
370 *) In main.cpp, type #include "ai_my_bot.h" at the beginning of the file near all other #includes.\r
371 *) In main.cpp, search for the function "void doGame()", and there find the part that says\r
372      "else if(gameType == 2) //Human + AI heads-up"\r
373     There, replace\r
374       game.addPlayer(Player(new AISmart(), getRandomName()));\r
375     into\r
376       game.addPlayer(Player(new AIMyBot(), getRandomName()));\r
377 *) The above changes "Human + AI heads-up". It's similar for the other game modes.\r
378 *) Implement the functions in the ai_my_bot.cpp files with your own AI specific code (replacing\r
379    or modifying the existing code of the copeid AISmart AI).\r
380 *) Look at the implementation of other AIs such as ai_smart.cpp, ai_checkfold.cpp, etc...\r
381    to learn about the C++ syntax.\r
382 *) You can use utility functions in the class Info, or utility methods from combination.h,\r
383      pokermath.h, random.h and util.h to help implementing your AI, or roll your own poker\r
384      math, databases, etc... to control your AI.\r
385 *) Look in the comments of the OOPoker code to learn the API of classes or headers and what\r
386      the purpose and usage of some classes or function is!\r
387 *) Look in the rest of this guide to learn more about C++, the API of OOPoker, tips, etc...\r
388 *) Then start the game, choose "Human + AI heads-up", and you can play against your AI!\r
390 ////////////////////////////////////////////////////////////////////////////////\r
391 ////////////////////////////////////////////////////////////////////////////////\r
392 ////////////////////////////////////////////////////////////////////////////////\r
393 ////////////////////////////////////////////////////////////////////////////////
395 Section 3.2 C++, Compiler and IDE.
396 ----------------------------------\r
398 3.2.1 C++\r
399 ---------
401 OOPoker uses C++. If you don't know how to use this programming language, this
402 chapter will help you on your way. There are some example AIs provided, so even
403 if you've never used C++ before, the code in these AIs might help you on your
404 way to learn the syntax!
406 First of all, place all the code of OOPoker (all the .cpp and .h files, and this
407 readme.txt file) in a directory.\r
409 3.2.2 Compiler\r
410 --------------
412 To begin programming, you'll need a C++ compiler, and an IDE or text editor
413 to write the code.\r
415 On Windows, you can use Code::Blocks, Visual Studio Express, or if all else fails, Dev-C++.\r
416 In these programs, you need to create a new C++ project, and then include all\r
417 the .cpp and .h files from OOPoker in your project. Then find the "compile" button\r
418 to compile the source, then find the "run" or "debug" button to run OOPoker.\r
420 A Code::Blocks project file (OOPoker.cbp) is provided so you can immediatly\r
421 get started if you use Code::Blocks: just open the project file, hit F9, and the\r
422 game compiles and runs.
424 When downloading Code::Blocks, get the version WITH Mingw compiler included, unless
425 you have a reason to choose a different compiler and tweak the Code::Blocks settings for that.\r
427 In Linux, this is very easy, there are plenty of text editors that can open
428 multiple source files (geany, Kate, gedit, ...), and the compiler is usually
429 built right in your OS (it's the g++ command), or easy to install with your
430 package manager (install gcc). To compile OOPoker, just go with your terminal
431 to the folder with the OOPoker code, and type "g++ *.cpp -W -Wall -Wextra -ansi".
432 After that, type ./a.out and OOPoker will run.
434 3.2.3 Language\r
435 --------------\r
437 Once you've managed to compile and run OOPoker, here's some information about
438 what you'll need to know about C++ to make AIs:
440 -the general syntax of C++ is similar to that of C, Java, C#, and other curly-brace
441 languages. If you've never used such a language before, try to look at the implementation
442 of the example AI's.
444 -A few typical concepts of C++ are required to program for OOPoker:
446 *) Headers and source files: C++ uses source files (.cpp) and header files (.h).
447    Typicall, in header files, you declare functions and classes, while in source
448    files you implement the actual code. This is why every OOPoker AI has two files,
449    for example "ai_call.cpp" and "ai_call.h".
451 *) Object Oriented programming: OOPoker AI's are object oriented, that is, they
452    all must inherit from the class "AI" or "AINamed" and implement a few functions
453    (explained later on).
455 *) struct <--> class: a struct and a class are exactly the same thing in C++,
456    except one little detail: in a class, members are private by default (until
457    you type "public:" somewhere, while in a struct, members are public by default
458    (until you type "privete: " somewhere). Good practice indicates to use classes
459    for true object-oriented programming, but to use structs for just grouping a few
460    variables together. OOPoker uses structs quite a lot, even in a few situations where
461    a class might have been more approriate. Sorry for that.
463 *) std::string: text strings. For a description of its functions,
464    please look here:
465    http://www.cppreference.com/wiki/string/start
467 *) std::vector<T>: a dynamic array type. For a description of its functions,
468    please look here:
469    http://www.cppreference.com/wiki/stl/vector/start
471 For the rest, if you've never used C++ before, I recommend you to follow the
472 steps of the "Really Quickly Getting Started" chapter.
474 ////////////////////////////////////////////////////////////////////////////////
475 ////////////////////////////////////////////////////////////////////////////////
476 ////////////////////////////////////////////////////////////////////////////////
477 ////////////////////////////////////////////////////////////////////////////////
479 Section 3.3: Implementing the AI
480 --------------------------------
482 The functions of class AI in ai.h have to be implemented in your class.
484 For implementing the AI, the most important function to implement is doTurn, because
485 that is where the decision is taken to fold, check, call, bet/raise or go all-in. Here's the
486 purpose of each function.
488 The manual below gives a rough description of functions, classes and structs. For exact
489 information about each value, member, etc..., please see the comments in the source code (e.g.
490 the commenfs of Action are in action.h, etc...).
492 *) virtual Action doTurn(const Info& info) = 0;
494 Make a decision for this turn: fold, check, call or raise? The output
495 of this function is an Action, the input is an Info.
497 The Action contains an enumeration indicating the type of action: FOLD, CHECK, CALL
498 or RAISE. Bet and raise are considered the same. All-in can be reached with both a
499 CALL and a RAISE action depending on your stack. Furthermore, the Action contains
500 a value, which is used only for the RAISE action. This value is the amount of money
501 you move from your stack to the table. It is NOT the amount you raise! It's the
502 amount you raise plus the call amount.
504 The Info contains all information you have available during this turn. That is:
505 your cards, the table cards if any, showdown cards if any, the index of you, the dealer,
506 everyone's stack and bet, the pot, the betting structure, the current round, the
507 amount of turns this round, the name of each player.
509 *) virtual void onEvent(const Event& event);
511 This function gives the same information as you get from the Info in doTurn, but
512 in a different format and sometimes some extra information. For example, if you're
513 all in or folded you can't make decisions anymore and thus get no more Info from doTurn,
514 but you still get the events.
516 An event is something like "a player calls", "a player quits", "the flop happened and
517 has those 3 cards", and so on. This is really linear, and in the correct order. You're not
518 required to implement this function for your AI. But you can implement it to remember events
519 and base decisions you'll do later in doTurn on this.
522 *) bool boastCards(const Info& info);
524 Called at the end of a deal, only if this AI wasn't required to show his cards.
526 Based on the info you can decide to show your cards or not. You can for example
527 decide to show them to prove you were not bluffing, or decide to not show them
528 to hide your playing style.
530 *) virtual std::string getAIName() = 0;
532 Return a unique name for your AI here. That way, when an AI battle occurs, you
533 can see which AI won. The AI name is not the same as a player's name. Multiple
534 players can have the same AI, those players will have a different name, but the
535 same AI name.
537 NOTE: AI's will never get the AI-name of other players, only their player name,
538 except completely at the end of the game when the rankings are provided.
539 So AI's normally don't know which implementation another player has as AI. The AI
540 can only learn the style of a player during a game by observing their behaviour.
542 ////////////////////////////////////////////////////////////////////////////////
543 ////////////////////////////////////////////////////////////////////////////////
544 ////////////////////////////////////////////////////////////////////////////////
545 ////////////////////////////////////////////////////////////////////////////////
548 Section 3.4: Putting your AI in the game
549 ----------------------------------------
551 Putting your AI in the game is done by adjusting the code in main.cpp. The in-game
552 options don't allow choosing AI's, instead you choose them in the C++ code, compile
553 the program, and then let the AI's battle. To change which AI's battle, change the C++
554 code again with the different AI's and start the game again. This allows the most
555 flexibility, and compiling this program doesn't take long.
557 See also Really Quickly Getting Started for some information about this, the final
558 steps describe exactly where in main.cpp to change something.
560 This chapter gives some info for the programmer who wants to do a little more.
562 To put your AI in the game, you have to create the Game instance and add
563 your AI to it with the addPlayer method. This is all already done in main.cpp.
565 In main.cpp, there's a part in the code where it'll add some players to the game
566 depending on which choice you made for "game type" in the in-game menu. For each
567 game type, you can change the AI's that are added to the game in the code. You can
568 also completely change everything in main.cpp if you want, to remove the menu and
569 just set up the game completely from within the code, including the betting
570 structure and so on.
572 In the "stock" main.cpp, all players get a random name with "getRandomName()". If
573 you don't like this, you can just use a fixed string there instead. If you want
574 to recognise which AI won, though, you don't need this player name. The name of the AI
575 itself is normally given in the log events and terminal output, so it shouldn't matter
576 that the player using your AI has a random name.
578 Once you finished this, you can start tournaments, e.g. try a AI battle heads-up of
579 your AI against AISmart. If your AI wins most of the time, it's a good AI!
581 ////////////////////////////////////////////////////////////////////////////////
582 ////////////////////////////////////////////////////////////////////////////////
583 ////////////////////////////////////////////////////////////////////////////////
584 ////////////////////////////////////////////////////////////////////////////////
587 Section 3.5: Utility Functions
588 ------------------------------
590 For implementing your AI, several utility methods are availabe. You are however
591 encouraged to create your own utility functions and poker algorithms in your AI
592 instead of only using the ones provided!
594 Useful utility methods are in the following classes and/or header files.
596 *) class Info from info.h (this is what you get in doTurn)
598 Has utility methods for simple things such as getting the total pot on the table,
599 the highest bet of a player, getting the amount of players that didn't fold yet, etc...
600 It has also got the "getMRatio()" function, which returns (your stack) / (small blind + big blind + total antes)
602 *) functions in pokermath.h
604 This has a mix of functions for various purposes.
606 getSklanskyMalmuthGroup and getRealPlayStatisticsEV can help deciding whether your cards are good or not (see
607 the description in pokermath.cpp in the implementation of these functions for more details).
609 isPair, isSuited, isConnector are handy for some more decisions about your hand cards.
611 splitIntoSuits, getAmountPerSuit can only be used for slow calculations similar to combination.h
613 eval7, eval7_index, eval5, eval5_index are very good functions for similating thousands of hands, see the section
614 "Fast Evaluation" for more information.
616 getWinChanceAgainst1AtFlop etc... use eval7 to calculate the win chance at flop, turn and river, simulating
617 every possible combination of extra table cards and hand cards of one opponent. This doesn't use random, it
618 tries every possible combination, which turns out to go fast enough with eval7.
620 *) functions in combination.h
622 the classes and functions in combination.h are a "naive" combination evaluator. For simulation work, use
623 eval7 in pokermath.h instead.
625 The naive methods here are useful for getting a nice name of a combination, finding out exactly which cards
626 are part of a combination, ...
628 *) random.h
630 This contains the function getRandom(), which returns a random value in the range 0.0-1.0, as well as some\r
631 functions for other possible return value ranges.
633 This random value is a non-blocking true random. It uses the randomness facilities of your
634 operating system. Usually (on Linux and Windows) this includes some random data from mouse movement,
635 network activity, etc... It is non-blocking, which means that if no true random data is available,
636 a semi-random-number generator is used instead.\r
638 Furthermore it contains getRandomFast(), which uses a very simple, but fast, pseudo random number generator.\r
639 There are some methods to seed it with true random values now and then.\r
641 getRandomFast() should be used when doing monte-carlo simulations of cards to calculate win equity, because getRandom() is too slow\r
642 to do even as little as 10000 random hand evaluations in a reasonable time.
644 *) card.h
646 Get the suit, value or an index of a card.
648 The value is 2-14. The ace has value 14 instead of 1 so that it's the highest.
650 The index value is currently not really used in OOPoker. Also, every poker and card
651 game has their own index system for cards, this is just yet another one. The values are:
653   unknown : -1
654   clubs   :  0=ace,  1=2,  2=3,  3=4,  4=5,  5=6,  6=7,  7=8,  8=9,  9=T, 10=J, 11=Q, 12=K
655   diamonds: 13=ace, 14=2, 15=3, 16=4, 17=5, 18=6, 19=7, 20=8, 21=9, 22=T, 23=J, 24=Q, 25=K
656   hearts  : 26=ace, 27=2, 28=3, 29=4, 30=5, 31=6, 32=7, 33=8, 34=9, 35=T, 36=J, 37=Q, 38=K
657   spades  : 39=ace, 40=2, 41=3, 42=4, 43=5, 44=6, 45=7, 46=8, 47=9, 48=T, 49=J, 50=Q, 51=K\r
659 *) util.h\r
661 A small amount of extra utility functions, to convert strings from/to text more easily than C++'s stringstreams,\r
662 "wrap" a number or get a nice rounded number near a given number (e.g. turning 69907 into 50000)
664 ////////////////////////////////////////////////////////////////////////////////
665 ////////////////////////////////////////////////////////////////////////////////
666 ////////////////////////////////////////////////////////////////////////////////
667 ////////////////////////////////////////////////////////////////////////////////
670 Section 3.6: Fast Evaluation (For Win Equity)
671 ---------------------------------------------
673 Sometimes poker AIs use simulations to calculate their odds. For simulations,
674 many possible 7-card combinations need to be checked and compared.
676 To be able to do as many evaluations as possible, it's preferrable to be able
677 to simulate thousands or millions of hands per second.
679 That is what eval5 and eval7 can be used for. These use the evaluators
680 developed by Cactus Kev, and by pokerai.org forum. It are amongst the
681 fastest evaluators avaible. All credit goes to these guys:
683 Cactus Kev (http://www.suffecool.net/poker/evaluator.html)
684 XPokerEval (http://www.codingthewheel.com/archives/poker-hand-evaluator-roundup)
685 2+2 poker forums (http://archives1.twoplustwo.com/showflat.php?Number=8513906)
686 mykey1961
687 pokercurious
689 Unless you found a faster one, you can use these functions for your AI if you
690 need to evaluate many hands.
692 Whenever you're tempted to use functions from combination.h and do multiple calls
693 to "combinationGreater", then use eval5 or eval7 instead. It is easily
694 1000 times faster.
696 Both eval5 and eval7 get cards as parameter, and return an integer.
698 If you call eval7 twice with different cards, and the integer returned by one call
699 is greater than the other, the cards of the greatest integer form a better combination
700 than the others.
702 Same for eval5.
704 Integer values returned by eval5 and eval7 may not be compared to each other, they use a different system.
706 The cards given as parameter for eval7 must be converted to an integer using eval7_index (do NOT use Card.getIndex()).
708 The cards given as parameter for eval5 must be converted to an integer using eval5_index (do NOT use Card.getIndex()).
710 This is because each algorithm uses its own specific, different, integer format for cards.
712 The implementation of getWinChanceAgainst1AtFlop demonstrates how to use eval7.
716 ////////////////////////////////////////////////////////////////////////////////
717 ////////////////////////////////////////////////////////////////////////////////
718 ////////////////////////////////////////////////////////////////////////////////
719 ////////////////////////////////////////////////////////////////////////////////
722 Section 3.7: OOPoker Code Overview
723 ----------------------------------
725 This section gives an overview of all the source code files of OOPoker. Not everything
726 of this is needed to implement your poker AI, because many source files are used for
727 running the game instead.
729 The order is alphabetical.
731 *) action.cpp, action.h
733 This is an action, the result of a doTurn call of an AI (fold, check, call, raise, and how much?)
735 *) ai.cpp, ai.h
737 This is the interface of the AI class you can implement\r
739 NOTE: a bit counter-intuitive, human players are also implemented using an AI. It's just an AI that\r
740 asks a human what to do through the user interface, instead of an AI that calculates it on its own then.
742 *) ai_blindlimp.cpp, ai_blindlimp.h
744 Very naive demo AI. This one calls blinds, then check-folds.
746 *) ai_call.cpp, ai_call.h
748 Very naive demo AI. It always calls.
750 *) ai_checkfold.cpp, ai_checkfold.h
752 Very naive demo AI. It always check-folds.
754 *) ai_human.cpp, ai_human.h
756 This isn't really an AI, it's the human player instead. This class is interesting
757 to look at, because it implements the AI in a different way, namely it asks
758 the human sitting in front of the computer what to do instead of calculating it
759 on its own. It also prints the information in the terminal for the human to read.
761 It has also got a timer implemented that can pause for half a second at every event,
762 to allow emulating gameplay where players think a while, otherwise everything goes
763 way too fast.
765 *) ai_raise.cpp, ai_raise.h
767 Very naive demo AI. It always raises, unless too much turns
768 passed (otherwise they'd keep raising forever, preventing the next round to start).
770 *) ai_random.cpp, ai_random.h
772 Very naive demo AI. It always does a random action. It has the potention to randomly
773 do something very good, or something very bad.
775 *) ai_smart.cpp, ai_smart.h
777 The most interesting demo AI. It uses some poker math and card evaluation to
778 make decisions. However, it still isn't that very smart, it's only smart compared
779 to the very naive demo AI's.
781 The intention is that you program a better AI than AISmart!
783 *) card.cpp, card.h
785 The Card class.
787 *) changelist.h
789 Lists recent enhancements and bugfixes. Also mentions incompatible changes,
790 that require making a few changes to existing bots to let them compile against
791 OOPoker again.
793 *) combination.cpp, combination.h
795 The combination class and functions to do slow but "nice" combination evaluation.
797 *) deck.cpp, deck.h
799 A deck of cards. This can be randomly shuffled, and then cards taken from the top.
800 Used to run the game. The randomness from random.h is used.
802 *) event.cpp, event.h
804 The Event struct, that can be sent to every player to give information about the game.
806 *) game.cpp, game.h
808 In these source files, the actual gameplay is implemented, this handles the betting rounds,
809 choosing the next dealer, pot division, etc... according to the rules of Texas Hold'm.
811 Could also contain a few utility functions useful to AIs, such as checking how will the pot be
812 divided amongst players depending on who would have the best cards.
814 The header file also contains a few general enums and structs, such as Round and Rules.
816 *) host.cpp, host.h
818 The host runs the game. This class has some power like deciding when to quit the game.
820 *) host_terminal.cpp, host_terminal.h
822 Implementation of host in the terminal. Draws a table representation now and then, and,
823 allows pressing "q" at any time to quit the game, even while AI's are working.
825 *) info.cpp, info.h
827 The Info struct, that can be used by AI's in doTurn to get current information.
829 *) io_terminal.cpp, io_terminal.h
831 Utility functions to use the terminal in Windows and Linux, draw the poker table
832 in ASCII-art, etc..., for the user interface.
834 *) main.cpp, main.h
836 This contains the main function that starts the program and sets up the game.
838 This is where you can insert your AI's to the game. See section
839 "Really Quickly Getting Started" for more information about this.
841 *) observer.cpp, observer.h
843 Apart from players, there can also be observers at the table. These don't play the game,
844 but receive events about what is happening. There are two implementations of the observer
845 interface: observer_terminal (terminal output) and observer_log (log file output)
847 *) observer_statkeeper.cpp, observer_statkeeper.h
849 Observer that updates a StatKeeper (see statistics.h). Used internally by the Game to
850 update statistics of players.
852 *) observer_terminal.cpp, observer_terminal.h
854 This observer is used in the AI Battle modes, so that you can see what the AIs are doing.
856 *) observer_terminal_quiet.cpp, observer_terminal_quiet.h
858 Very similar to observer_terminal, but shows less events, causing the game to possibly
859 run faster.
861 *) observer_log.cpp, observer_log.h
863 This observer is used in all game types. It appends all events to a file "log.txt". This
864 allows seeing the history of all games ever. Since it appends, the file will become bigger
865 and bigger, so delete it if you don't need it anymore.
867 *) player.cpp, player.h
869 Information about players (such as their stack, AI, etc...). Used to run the game.
870 Not accessible by poker AI's, they get this information in the Info struct instead.
872 *) pokereval.cpp, pokereval.h
874 This is the code made by Cactus Kev and 2+2 poker forums for fast poker hand evaluation, but
875 the OOPoker interface for this is actually in pokermath.h.
877 *) pokereval2.cpp, pokereval2.h
879 This is code I found later. It's faster than pokereval.cpp and doesn't use a handranks.dat file. So
880 the 7-card evaluator from pokereval.cpp is made obsolete (but its 5-card evaluator is still used).
882 The OOPoker interface for this is actually in pokermath.h.
884 *) pokermath.cpp, pokermath.h
886 Utility functions for poker AI's.
888 *) random.cpp, random.h
890 Getting an almost random number. Used both for running the game (shuffling the card
891 deck) and some AI's (making unpredictable decisions). Slightly more true-random
892 than C's "rand()".
894 *) rules.cpp, rules.h
896 Contains a struct with the current game rules (blind values, win condition, ...).
898 Also contains the Round enum (not really a rule, but it fit the best here).
900 *) statistics.cpp, statistics.h
902 This contains a struct with player statistics, and a StatKeeper that can update
903 stats based on the game events. This is used by the game to provide player statistics
904 at the end, but it can also be used by your AI to keep track of players if you wish so.\r
906 To use it in your AI, you have to make your own StatKeeper object and forward all events\r
907 you receive in onEvent to the StatKeeper.
909 If you need more statistics about players than this for your AI, implement a different
910 StatKeeper in different source files, since those from statistics.h are standard for the
911 game itself and thus supposed to stay as they are.
913 StatKeeper is also a good demonstration of getting information about the game from
914 events.
916 *) table.cpp, table.h
918 Information about the table, such as who is sitting on it. Used to run the game.
919 Not accessible by poker AI's, they get this information in the Info struct instead.
921 *) unittest.cpp, unittest.h
923 This are unit tests to validate OOPoker, especially to check if it runs the game
924 correctly according to the Texas Hold'm rules.\r
926 NOTE: good unit tests work automatically, and say at the end how many errors were found.\r
927 The unit test of OOPoker currently doesn't report errors, it only gives output that\r
928 requires human inspection to validate its correctness!\r
930 *) util.cpp, util.h\r
932 A small amount of extra utility functions, to convert strings from/to text more easily than C++'s stringstreams,\r
933 "wrap" a number or get a nice rounded number near a given number (e.g. turning 69907 into 50000)\r
935 ////////////////////////////////////////////////////////////////////////////////\r
936 ////////////////////////////////////////////////////////////////////////////////\r
937 ////////////////////////////////////////////////////////////////////////////////\r
938 ////////////////////////////////////////////////////////////////////////////////\r
941 Section 3.8: Making a Graphical or Webserver Interface\r
942 ------------------------------------------------------\r
944 OOPoker is currently only implemented to work in the console. This is because so\r
945 far the program focuses on the math and poker rules, instead of on the user interface.\r
947 However, it is possible to make a graphical client, or webserver version that can be\r
948 played in a browser, without doing too radical changes:\r
950 What has to be done is to create an implementation of the classes Host, AI and Observer\r
951 that interact using the alternativ einterface rather than with the console. Those 3 classes\r
952 will also need to work together a bit, because they use the same input and output channels.\r
954 For the terminal version of OOPoker, the clases HostTerminal, AIHuman and ObserverTerminal\r
955 all use the console.\r
957 If you implement graphical or webserver versions of these, then you can plug in those\r
958 into the Game instead of the terminal ones.\r
960 Apart from making these 3 classes, the main function itself from main.cpp also has to be changed,\r
961 currently it uses the terminal to ask what type of game to play.\r
963 Note that OOPoker's terminal implementation is designed to work on both Windows and Linux. Other\r
964 interfaces should preferably also be multi-platform.
966 ////////////////////////////////////////////////////////////////////////////////
967 ////////////////////////////////////////////////////////////////////////////////
968 ////////////////////////////////////////////////////////////////////////////////
969 ////////////////////////////////////////////////////////////////////////////////
972 Chapter 4: Texas Hold'm Rules\r
973 -----------------------------\r
975 OOPoker uses fairly standard Texas Hold'm rules. The points below are just a few
976 clarifications. Extra features (such as increasing blind and limit games) might
977 be added to OOPoker later.\r
979 *) It's no-limit texas hold'm, so raises can be as big as you want\r
980 *) When raising, the raise amount must be at least as big as the previous raise
981    amount (initially this is the big blind)\r
982 *) Apart from the small blind and big blind, an optional ante can be configured.\r
983 *) Tournaments are currently always at a single table, with two possible win conditions:\r
984    -the last surviver\r
985    -the one who earned most money after a fixed amount of deals with rebuys\r
988 ////////////////////////////////////////////////////////////////////////////////
989 ////////////////////////////////////////////////////////////////////////////////
990 ////////////////////////////////////////////////////////////////////////////////
991 ////////////////////////////////////////////////////////////////////////////////
993 Chapter 5: Contact Information
994 ------------------------------
996 Feel free to contact me for requests related to OOPoker.
998 My name is at the bottom of the copyright message. My email address is first name
999 dot last name at gmail dot com.
1001 OOPoker is hosted here: https://github.com/lvandeve/oopoker
1003 ----------------------------------
1005 Copyright (c) 2010-2014 Lode Vandevenne
1006 All rights reserved.