card ranking

This is a discussion on card ranking within the C Programming forums, part of the General Programming Boards category; i am making a card game(texas hold em) and so far this is what i have: creates a deck with ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    card ranking

    i am making a card game(texas hold em) and so far this is what i have:


    creates a deck with all the suits and values(52 cards) and is stored in an array.
    picks cards at random and deals each player(9) two cards, also stored in an array.
    picks five community cards at random and stores them into an array.


    now this is the part where i am having a bit of trouble. finding the ranks of the hands. now all the suits and values are stored as integers like this:

    values(on the left is the stored number and on the right is what it represents):

    0=ace
    1=2
    2=3
    3=4
    4=5
    5=6
    6=7
    7=8
    8=9
    9=10
    10=J
    11=Q
    12=K

    suits:

    0=club
    1=diamond
    2=spade
    3=heart


    a player may use 5 of the 7 cards to make up their hand. im not quite sure how to go about checking for this. a sample array of the community cards plus the players cards would look something like this:

    4 9 2 12 11 4 8

    if someone could point me in the right direction of give me a sample on how to do it i would appreciate it. thanks.

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Just take the max score of every combination of five cards. If you have a function that calculates the score of a five card hand, this becomes almost trivial...
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    5
    as an update, i made another array that puts all the cards into ascending order to better find the hand rankings.

    happy, thanks for the reply. do you think you could explain this concept a little better? seems a little vague to me. also, there are 7 cards to deal with and the player doesn't actually have to use any cards in their hand to make a hand they can use the board.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    There are 7 cards, so there are 7 choose 5 possible hands per player. For each possible hand, evaluate the hand on a numerical scale and take the largest score as that players hand. The player with the overall largest score wins.

    There are a finite number of hands with a finite number of card combinations to build each of those hands. Choose a method for quantifying each on a linear scale and use this method for your evaluation. Alternatively, you could categorize hands first, then quantify only in the case of a tie between categories (ex. full house, straight,...).

  5. #5
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Doesnt' matter, there are still only 7 choose 5 combinations, since order doesn't matter (21 to be exact).

    So to do this, you can proceed systematically. I'll show you how to do this with 2 choose 4.
    You have 4 objects : 1 2 3 4. The first combination of 2 is (1,2). The next one is (1,3). After, (1,4). Next is (2,3) (not (2,1), you already picked that one, remember ?). Then (2,4). Then, finally (3,4).

    Do you notice the trend develloping here ?

    EDIT : Beaten to the thread, it would seem...
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    5
    i get what you said, so basically there is no way to get around having a ton of if statements?

    thanks for the replys.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Write a function to check each type of hand. Pass your hand to it. Return something to indicate success or failure. You can teach yourself the fun of function pointers and just use a nice little loop.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    I don't see where you'd be seeing a ton of if statements.
    There'd only be one for every type of combination (flush, straight, etc...)
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 11:06 AM
  2. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 05:07 AM
  3. Vector out of range program crash.
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2008, 05:37 PM
  4. Segmentation Fault - aaaaaaaah!
    By yogibear in forum C Programming
    Replies: 6
    Last Post: 10-01-2007, 04:21 AM
  5. Blackjack
    By Tommo in forum C Programming
    Replies: 10
    Last Post: 06-20-2007, 09:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21