I've been a poker player for a few years. I don't usually play "live" games where money is involved as I'm not the gambling type. I've only played a scratch-off lottery card once and that was on my 18th birthday. I do however play online for fake cash (points) and with friends for bragging rights. It's a fascinating game that you can improve at. I've managed to keep my fake chip stack above 200 K for a while whereas I used to be a more volatile player. I've wondered for a while now if I could create a winning poker agent based on what I've learned at the table and what I know about machines.
Poker is a game with a lot of unknowns and depends more on probability, your read of a player (profiling), and luck (chance). Given everyone has the same amount of luck over a long period of time, the players with the best math skills and "reads" will have the larger stack in the long run. So we don't have to program how to deal with luck just now. But later we can add stack protection to limit the agent's losses due to bad luck.
My initial approach to building a poker agent will be based on Mick West's article Texas Hold'em AI. Some people still call it Texas Hold'em but the more general term for it is No-Limit Hold'em. I'm not from Texas so I'll go with the latter. Mick gives a method for creating a simple implementation based on what he learned while working on the World Series of Poker game. Later I'll be using what I learned with G.A. and N.N. to spawn multiple species of smart agents each with unique styles of playing.
I've begun by defining my data types for suit, rank, cards, hand, and hand type. I've created a struct of 4 16bit words to hold a single hand of poker. Each of the 4 words represents a suit (numbered 0-3) of clubs, diamonds, hearts, and spades. There are 13 ranks in each suit (0=2 and 12=A). We can represent that a card is in a hand by setting the correct bit in the proper suit. I've created a function to set the proper bits given a number representing the card (numbered 0-52). The card = suit*13+rank, suit=card/13, and rank=card%13. There are nine hand types in poker. 0:no pair, 1:pair, 2:two pair, 3:set, 4:straight, 5:flush, 6:full house, 7:quads, and 8:straight flush.
My next step was to build a function to return a hand type of a given hand. The agent will need to know where it stands given its hole cards and the community cards. Mick combined this into a function for creating hand values, discussed later, but I've decided to separate the two as they really do different things. The hand type function is a lot of comparisons and table lookups. Limiting the number of cards in a player's hand allows me to make certain logical assumptions. An example of this is if there are 5 cards in a given suit then the hand type is a flush and it can then check for a possible straight flush. Of course no flush check is necessary unless there are at least 5 cards in the hand. The whole function continues on like this and is a prime target for optimization. Yay!
That's as far as I've gotten so far. Next I'll need to create comparable hand values from the hand types so the agent knows who won and who lost. You can see a print out of hand values and hands below.
Also I've posted some new photos on my site, including one of me flying this neeto toy my son got last Christmas.