Two Plus Two Newer Archives

Two Plus Two Newer Archives (http://archives1.twoplustwo.com/index.php)
-   Science, Math, and Philosophy (http://archives1.twoplustwo.com/forumdisplay.php?f=49)
-   -   Programming a Poker Game (http://archives1.twoplustwo.com/showthread.php?t=547026)

PBAR 11-15-2007 05:37 PM

Programming a Poker Game
 
I'm taking an AI course at university and for a project we are making a poker game between two players. The game is five card stud with no draws.

Anyways, I'm wondering the best way to go about this. I basically need a function that deals a hand and one that evaluates a hand. As of now, I am representing the deck as a 4x13 array of one's, and when a card is dealt its index is changed to a zero. For the poker hand, I thought of representing it with a 2x5 array, where the first row are the card values and the second is the suits. This may not be the best approach and any suggestions are appreciated. I'm an engineering student and not a computer scientist.

I'm wondering what the best way to make the hand evaluator is. Any suggestions are again appreciated. Thanks.

(This will be done in C++)

Neuge 11-15-2007 05:43 PM

Re: Programming a Poker Game
 
Your shuffling algorithm looks really inefficient and is almost certainly not truly random. You should implement a Knuth Shuffle which shuffles the whole deck before any cards are dealt and you can then just deal from the top of the deck (i.e. deck[0], deck[1]...).

gumpzilla 11-15-2007 05:44 PM

Re: Programming a Poker Game
 
My first suggestion would be to see if the source code for pokenum is publicly available. I'm guessing it probably is, and it will likely have a good answer for you.

I've thought about this a little, since I thought it would be interesting to try and work out a good representation for these kinds of things myself. One idea I had (which I haven't pursued in great depth) is to try and use regular expressions for doing hand evaluation. I don't know how easy that is in C++, though.

Subfallen 11-15-2007 05:51 PM

Re: Programming a Poker Game
 
Enumerate suits as 0-3 and ranks as 0-12. Then represent each card as an integer, where:
- ID = suit * 13 + rank
Then for card 'c':
- suit of c = c / 13
- rank of c = c % 13

The deck can now be a one-dimensional array. If you order suits Clubs, Hearts, Spades, Diamonds (0-3), then 0 is the 2[img]/images/graemlins/club.gif[/img] and 51 is the A[img]/images/graemlins/diamond.gif[/img].

uDevil 11-15-2007 05:52 PM

Re: Programming a Poker Game
 
Check out the software forum.

Don't reinvent the wheel if you don't have to. I think there is some C++ source out there, but you'll have to search for it. There is lots of code in C and Java. For example:

https://gna.org/projects/pokersource

http://spaz.ca/poker/

For poker related AI information:

http://www.cs.ualberta.ca/~games/poker/

Paragon 11-15-2007 07:35 PM

Re: Programming a Poker Game
 
All of the comments are pretty good. As for representing a hand, you can use 4 integers to neatly do this. Each integer represents one of the four suits, and the bits of the integer determine if a particular card of that suit is in that player's hand. Now you can do some neat bit tricks to quickly figure out the hand strength... Like if there are 5 one's in the spade integer, you know the hand is at least a flush. Or if you bitwise AND the four integers together into one integer, and that still has a single bit set, then you know you have quads. Anyway, all of this is in the eval code of pokenum or whatever the open source project is, although they also use huge precomputed lookup tables for 5 card hands I think.

tshort 11-15-2007 10:02 PM

Re: Programming a Poker Game
 
As someone mentioned, there is plenty of freely available poker source. Why re-create the poker engine if your doing this for AI purposes?

PBAR 11-16-2007 02:20 PM

Re: Programming a Poker Game
 
Thanks for the replies, it should help me get a good start. The prof has a tendency to make us program things that aren't relevant to the AI itself so I doubt we can use the open source code...

Phil153 11-16-2007 11:54 PM

Re: Programming a Poker Game
 
What is your prof looking for? OO design or speed?

spacegambler 11-19-2007 01:38 AM

Re: Programming a Poker Game
 
There is an excellent explanation of an efficient method for 5-card hand evaluation at:
http://www.suffecool.net/poker/evaluator.html


All times are GMT -4. The time now is 06:26 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.