Two Plus Two Newer Archives  

Go Back   Two Plus Two Newer Archives > Other Topics > Science, Math, and Philosophy
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2007, 05:37 PM
PBAR PBAR is offline
Member
 
Join Date: Feb 2006
Posts: 57
Default 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++)
Reply With Quote
  #2  
Old 11-15-2007, 05:43 PM
Neuge Neuge is offline
Senior Member
 
Join Date: Jul 2004
Posts: 784
Default 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]...).
Reply With Quote
  #3  
Old 11-15-2007, 05:44 PM
gumpzilla gumpzilla is offline
Senior Member
 
Join Date: Feb 2005
Posts: 7,911
Default 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.
Reply With Quote
  #4  
Old 11-15-2007, 05:51 PM
Subfallen Subfallen is offline
Senior Member
 
Join Date: Sep 2004
Location: Worshipping idols in B&W.
Posts: 3,398
Default 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].
Reply With Quote
  #5  
Old 11-15-2007, 05:52 PM
uDevil uDevil is offline
Senior Member
 
Join Date: Jul 2003
Location: Cloudless climes and starry skies.
Posts: 2,490
Default 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/
Reply With Quote
  #6  
Old 11-15-2007, 07:35 PM
Paragon Paragon is offline
Senior Member
 
Join Date: Sep 2004
Location: Maryland
Posts: 212
Default 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.
Reply With Quote
  #7  
Old 11-15-2007, 10:02 PM
tshort tshort is offline
Senior Member
 
Join Date: May 2005
Posts: 1,143
Default 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?
Reply With Quote
  #8  
Old 11-16-2007, 02:20 PM
PBAR PBAR is offline
Member
 
Join Date: Feb 2006
Posts: 57
Default 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...
Reply With Quote
  #9  
Old 11-16-2007, 11:54 PM
Phil153 Phil153 is offline
Senior Member
 
Join Date: Oct 2005
Posts: 4,905
Default Re: Programming a Poker Game

What is your prof looking for? OO design or speed?
Reply With Quote
  #10  
Old 11-19-2007, 01:38 AM
spacegambler spacegambler is offline
Junior Member
 
Join Date: Oct 2007
Posts: 1
Default 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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:35 PM.


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