Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Poker Intel

Sign in to follow this  


As I continue with the demon game, I'm instantly back doing what I don't want to talk about in my journal, artwork. So screw it, I'll keep working on that and talk about something else until I get to the nuts and bolts of the game play.

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.
Sign in to follow this  


Recommended Comments

Interesting. I've played a fair bit of poker with friends - never for much more than a few-quid buy-in though. Can't claim to be much good at it but I do enjoy playing [grin]

Seems that studying the mechanics of various (supposedly simple) games opens up the door to a huge number of sub-fields within computer science. Makes it both challenging but also fairly interesting I find.

I'll be interested in seeing where this goes - although please dont take your "creation" down to Vegas. If the film 'Casino' is anything to go by they don't like cheating [lol]


Share this comment

Link to comment
I wrote some 'poker hand scoring' stuff at one point. The way I solved it was to give every unigue hand a specific numeric value. Now, this is easier than it sounds. I just gave each hand type a different place in the number space. Then I just started at the bottom.
I first sorted the cards by face value, then I started at the bottom, and totalled the score for every combination the hand produced. Starting with the lowest card, and working up through high card to pair all the way to straight flush, we determine if the hand matches that type, and if so, we multiply the value of the highcard in that combination with the number of steps we've taken upward, and accumulate the total. It gets complicated with flushes and such that have to account for every card that makes up the flush.
The result is a single score number. The hand with the highest score wins. If you're interested in knowing more detail about the algorithm, let me know.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!