Smash Vegas

Avatar

Anatomy of a pokerbot - first steps in coding

Now that we have decided on our strategy it’s time to start coding the bot.  We’re going to use the default formulae, so I’d recommend you take a look at this.

We will need to be familiar with some of the symbols openholdem uses.  You can find a complete list here but these should suffice for now;

  • call tells us the current cost to call.
  • bet is the amount of a single bet for the current round.
  • pot is the current amount in the pot.
  • br is the current bet round (1=preflop,2=flop,3=turn,4=river).
  • prwin is our probability of winning the hand (estimated with a monte carlo simulation).
  • prtie is the probability of a tie for the win.
  • prlos is our probability of losing the hand.
  • callshort is the total amount which will be added to the pot if all players call.
  • raisshort is the total amount which will be added to the pot if all players still in the hand call one bet.  I.e. it is callshort + bet * (number of players still in the hand).

Let’s start with coding the formulae for the expected values of calling and raising; f$evcall and f$evrais.  Going with the strategy we decided last time we have;

##f$evcall##
0                         // start at 0
- call                    // my cost to call
+ (pot+call)           // the minimum possible pot
* (prwin+prtie/2)    // my chances of winning

and

##f$evrais##
0                                                 // start at 0
- call                                            // my cost to call
- bet                                            // my cost to rais

+

(

(pot+call+bet*2)                            // the minimum possible pot

+ (raisshort-call-bet*2)*0.5             // guessing that half those playing will call

)

* (prwin+prtie/2)                           // my winning chances

Note that ##…## tells openholdem that it is the start of a function and // tells openholdem that what follows is a comment (to help those reading the code) and should be ignored.  In the following formulae we’ll also use || (which means OR) and && (which means AND).  For a full description of the openholdem scripting language look here.

We’ll use the all in function f$alli to look for conditions where we always want to bet.  It will never evaluate as true in limit poker since we can’t go all in, but we can use it as a convenient place to store our “safe” conditions where we want the bot to always bet.

##f$alli##
0                                          // do nothing by default
|| [ prwin >= 1.00 ]                 // we have the nuts
|| [ prtie >= 1.00 ]                  // sure tie

Now we need a raise function f$rais to look if f$evrais is greater than both 0 (folding EV) and f$evcall.

##f$rais##
0                                          // default is do not raise
|| [ f$alli ]                              // safe conditions
|| [ f$evrais > 0  &&                 // positive EV
f$evrais > f$evcall ]                 // better to raise than call

Our call function f$call now simply has tell openholdem to call if f$evcall is greater than zero, or if call is equal to zero (in which case we can check).

##f$call##
0                                         // default is do not call
|| [ f$alli ]                            // safe conditions
|| [ f$evcall > 0 ]                  // positive EV
|| [ call <= 0.00 ]                  // zero call amount (check)

Well done.  Put these into the formula editor and you have coded your first pokerbot.  If you have any questions feel free to ask.

Continue to see ways to improve on this.

No Comments, Comment or Ping

Reply to “Anatomy of a pokerbot - first steps in coding”