I have some classes so far.

  • Hand stores information like SB, BB, ante, collection of Players
  • HandState inherits from class Hand. has members like phase {POSTING BLINDS, PREFLOP, FLOP, TURN, RIVER, SHOWDOWN }, pot. I consider every action in a poker hand as a handState. Players post ante (if any), Small blind and big blind posts blinds, the first player to act (UTG) calls the blind, the 2nd player (UTG+1) raises, etc...
  • Player members: name, position, list of actions so far, stack, etc...
  • Action members: type {FOLD,CALL, RAISE, RERAISE}, amount

The program receives as input the blinds, players, which player to act. Since the input I get is string (its a console program) I have to build the root handState.

After I have the root handState, I can build a gameTree where every node is a handState. eg.:

stacks = "1000,2000,2300,1400,230";
actions = "200";
playerToAct = 2;
BB = 400;
SB = 200;

function makeRoot()
{
    stacks = makeArray(stacks)
    for(i=0; i < stacks.size; i++)
    {
        player = new Player;
        player.position =  "UTG"
        if (i > 0)
            player.position += i;
        if (i == stacks.size-2)
        {
            player.position = "SB";
            player.bet(SB);
        }
        if (i == stacks.size-1)
        {
            player.position = "BB";
            player.bet(BB);
        }
    }              
}

My problem that Player and HandState has no connection. What if player has not enough chips to pay the BigBlind (230<400)? SB has enough chips, but if he bets 200, HandState's pot wont know about it? Should I keep track in both class?

//HandState
player.bet(200);
this.pot += 200;

//Player
bet(amount)
{
    this.stack -= amount;
    this.actions.push(new Action(amount, "BET"));
}

I hope there is some seasoned programmer with some poker knowledge to tell some opinion, critique my approach.

Your basic structure in poker is a table. If you have a tournament you have a collection of tables.

A table has a limited number of seats which are ordered in a sequence around the table.

Each seat can have a player, but a seat can be empty.

Before each hand is played the dealer is selected at the next non-empty seat going clockwise.

A player has a stack and hole cards (I'm assuming texas hold'em other variants require a different approach (ideally the approach should be injected into the player)).

The table also have a collection of pots. At the start of the hand there is one empty pot, as the bidding continue there may be added more pots.

Each pot contains a chip count and a list of players included in that pot.

At the start of each hand the blinds and antes are collected.

If a player does not have enough chips to pay the ante or the blinds a new pot is created (side pot).

Let us assume no ante and blinds of 200 and 400 chips.

The big blind is supposed to pay 400, but has only got 230 and goes all-in.

The first pot (the main pot) now contains 200 (small blind) and 230 (big blind) chips, and the players SB and BB. The pot also contains the information that the first 230 from players in this round of betting should go into this pot.

A new pot is created which 0 chips and the player SB.

To make this simple one player X calls 400. 230 chips and the player X is added to the first pot. 170 chips and the player X is added to the second pot.

The rest of the players fold as well as the small blind. When the small blind folds he is removed from the first pot.

We now have the first pot with (200+230+230) 660 chips and the players BB and X and we have the second pot with 170 chips and the player X.

As there is only one player in the last pot, there is no more bidding.

The flop, turn and river plays out and the winner is found.

As X is the only player in the second pot, that pot goes to player X.

The best hand of BB and X gets the first pot or it could even be split between the two players.

  • I'd just keep track of how much money each player put into the pot instead of keeping track of pots. Produces the same result but is much simpler. – CodesInChaos Sep 12 '16 at 20:14
  • @CodesInChaos But then you'll have to recalculate the main and side pots every time you'd update the display during play (assuming you'd like your players to be able to see them during play) and of course when the hand is over. I believe that the logic that goes into calculating the pots is simpler when it is done on the fly. If you want players to be able to hover the mouse over each pot to see who is in which pot, you don't have to recalculate that as well at each update of the display. – Bent Sep 13 '16 at 7:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.