please help with poker game

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 1
Reputation: Renas is an unknown quantity at this point 
Solved Threads: 0
Renas Renas is offline Offline
Newbie Poster

please help with poker game

 
0
  #1
Oct 22nd, 2009
hi everyone
i'm new in programing, so don't judge me if i will say something stupid...
i'm trying to write i poker game in C++ but have faced with several problems, the first one is how to determine a winner...
for example i player hand is:
Ace of spades card number is: 39
Four of spades 42
Six of spades 44
Ace of diamonds 0
King of diamonds 12
dealer:
Four of diamonds 3
three of spades 41
Seven of hearts 19
three of hearts 15
Five of diamonds 4
how to determine that player wins...? i could write down all combination... but there is thousands of them...
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,675
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso
 
0
  #2
Oct 22nd, 2009
You need to write a couple of hand scoring functions. You don't look for all possible combinations, but look at a player's hand and determine what, if any, of the poker hands it constitutes.

In evaluating a hand, you need to look at first the value of the cards, disregarding suit. Is there a pair, three of a kind, four of a kind? If there's a three of a kind, are the remaining cards a pair? If none of those, are the five cards in sequence, to make a straight? Lastly, check if all the cards are of the same suit, for a flush. The results of these last two tests tell if it's a straight flush.

One tip in creating these functions - sort the cards in the hand by value - makes most of these evaluations easier.

That's a start for evaluating a hand. Comparing two hands to determine a winner will add more complexity and further testing if hands are same type. But you can work on that after the basic evaluation is complete.

So, write us some code, show it, and we'll go from there.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster
 
0
  #3
Oct 22nd, 2009
I assume that each suit has a specific numbers associated to them; i.e. Diamonds are 0 - 12, Hearts are 15 - 27, etc. With that in mind, you can do some things to help.

Like check if the cards are in the same suit by dividing the card number by 13 (any Diamond = 0, Heart = 1, etc). Or modding the card number by 13 to see if they have a pair/three of a kind/four of a kind (Ace = 0, Jack = 11, etc) or even if they have a straight.

I think those two will along will allow you to do most of the work.

You might consider ranking the suit 2 - Ace so that 2 = 0 and A = 12, that way you can determine which card is highest without making a special case for the ace. 3 of Diamonds is obviously lower the 6 of hearts (dia3%13 = 2, and hea6%13 = 5) but it isn't obvious that the Ace of diamonds is higher than the heart (diaA%13 = 0, and head6%13 = 5).

I would also suggest creating a hand rank like in this image.
http://img2.baltgames.lv/v2/usergalleries/199601.jpg
That way when you determine that player one has a pair of aces, you can mark their hand with a 9 and mark the dealers hand with a 9, see that both contain a pair, then compare the card number and see Ace beats 3.

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 302
Reputation: Clinton Portis is an unknown quantity at this point 
Solved Threads: 31
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Whiz
 
0
  #4
Oct 22nd, 2009
Are you feeling lucky...

I'm gonna go all-in on this; I've written a few ascii table games so I know what ye' are talking aboot here.

There are of course many ways to do this. I would suggest to write specific functions to test every possible winning situation that can occur in the game of poker. Then you can pass players 'hands' into each function. The functions could be designed to return TRUE for each test.

Without getting hot and heavy into each function definition, I'll just give you a general overview of the suggested design:
  1. struct card{
  2.  
  3. string suite;
  4. int value;
  5. };
  6.  
  7. //Function prototypes:
  8. bool is_one_pair(card&);
  9. bool is_two_pair(card&);
  10. bool is_three_of_kind(card&);
  11. bool is_straight(card&);
  12. bool is_flush(card&);
  13. bool is_full_house(card&);
  14. bool is_four_of_kind(card&);
  15. bool is_straight_flush(card&);
  16. void high_card(card&);
  17.  
  18. //create containers that will represent a hand for each player
  19. card player1_hand[5], player2_hand[5], player3_hand[5], player4_hand[5];
  20.  
  21.  
  22. //Now the part ye' been askin' aboot
  23.  
  24. //Somewhere along the line you can do something like this:
  25.  
  26. if (is_one_pair(player1_hand))
  27. {
  28. //code to handle hand containing 1 pair
  29. }
  30. else if(is_two_pair(player1_hand))
  31. {
  32. //code to handle hand containing 2 pair
  33. }
  34. else if(is_three_of_kind(player1_hand))
  35. {
  36. //code to handle hand containing 3 of a kind
  37. }
  38. else if(is_straight(player1_hand))
  39. {
  40. //code to handle hand containing a straight
  41. }
  42. else if(is_flush(player1_hand))
  43. {
  44. //code to handle hand containing a flush
  45. }
  46. else if(is_full_house(player1_hand))
  47. {
  48. //code to handle hand containg a full house
  49. }
  50. else if(is_four_of_kind(player1_hand))
  51. {
  52. //code to handle hand containing 4 of a kind
  53. }
  54. else if(is_straight_flush(player1_hand))
  55. {
  56. //code to handle a straight flush
  57. }
  58. else
  59. high_card(player1_hand));
  60. {
  61. //get the high card of the hand
  62. }

Well, hopefully that will give ye' something to think about. I wrote this pseudo code based on 5 card draw poker, but can be easily modified to other poker variants.

One more consideration: some people handle the 'royal flush' as a special case.. but in actually it's just a straight flush.
Last edited by Clinton Portis; Oct 22nd, 2009 at 2:27 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 302
Reputation: Clinton Portis is an unknown quantity at this point 
Solved Threads: 31
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Whiz
 
0
  #5
Oct 22nd, 2009
More Considerations: Some hands will test TRUE in more than one function; example: a hand containing 2-pair will also test TRUE for 1-pair... a hand containing a straight-flush will also test TRUE for a straight and for a flush, so be prepared to handle these situations accordingly.
Last edited by Clinton Portis; Oct 22nd, 2009 at 2:42 am.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC