Announcement

Collapse
No announcement yet.

C++ question: find type of a hand of 5 cards...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C++ question: find type of a hand of 5 cards...

    Hi,
    I'm not sure if this is the correct forum to post questions about C++ programming. Please excuse me if this is not.
    The program is to randomly draw 5 cards (called a hand) from a 52-card deck. It then has to find out what type (pair, 2 pairs, flush, straight,...) the hand is classified to.
    Now I'm stuck at the second part, which is how to find out what is the type of the hand. I have no clue how to find out.
    Any C++ savvy here who could help me? Any suggestion would be greatly appreciated.
    Thank you.
    Trung
    MSI K8N Neo 2 Platinum
    AMD Athlon 64 3200
    1024 MB PC3200 RAM
    WD 160 GB HDD
    2 x 80 GB Maxtor HDDs in RAID 1
    ATI 9500 64 Videocard
    Pioneer 108 DVD-RW
    Pioneer 117 DVD-ROM
    Windows XP Professional SP2

  • #2
    Hello Trung
    Can you post your existing code, so I can adjust my answer accordingly?

    Chen

    Comment


    • #3
      hi ChenSoft,
      Here is the link to it
      http://pages.infinit.net/ttddhh/cards.cpp
      Trung
      MSI K8N Neo 2 Platinum
      AMD Athlon 64 3200
      1024 MB PC3200 RAM
      WD 160 GB HDD
      2 x 80 GB Maxtor HDDs in RAID 1
      ATI 9500 64 Videocard
      Pioneer 108 DVD-RW
      Pioneer 117 DVD-ROM
      Windows XP Professional SP2

      Comment


      • #4
        Pseudo Solution

        Hello trung
        I thought I'll have time to review your code but I can't do it right now.
        Any way the solution should be as followed:
        1. Randomize 5 cards.
        2. Sort the cards (by their faces 1-13 or something like that).
        3. Make an int array with the size of 13, run through the cards and fill the array with the number of appearances of each card. You can also make a temp variable to store the number of pairs or threesomes you've found (by checking if the suits are the same).
        4. With the information you gathered you should be able to build a large "switch()" block with cases that represent the different hands.

        Good lock and maybe I'll have time to review your code later.

        Chen

        Comment


        • #5
          Hi ChenSoft,
          Thanks for trying to help me. However, since I'm a beginner in C++ programming, it's difficult for me to write actual codes using your Pseudo.
          Anyway, I've tried but still I can't find out what is the logic behind the procedure to find out what type the hand of cards is classified to. If you can suggest me a Pseudo code specific to this part, that would be great.
          Trung
          MSI K8N Neo 2 Platinum
          AMD Athlon 64 3200
          1024 MB PC3200 RAM
          WD 160 GB HDD
          2 x 80 GB Maxtor HDDs in RAID 1
          ATI 9500 64 Videocard
          Pioneer 108 DVD-RW
          Pioneer 117 DVD-ROM
          Windows XP Professional SP2

          Comment


          • #6
            Its been a while since I have done anything like this.. but here is hopefully some ideas.

            Each card has a number (1-13) and a suit (1-4)

            You sort the 5 cards by number (1 to 13)

            You have an array that checks the number of each of the five cards and increments a counter (for each number)

            Eg. Check for ones - no ones... counter_1 = 0 ... check for twos... one two... counter_2 goes up one so that counter_2=1 (the counter numbers get stored in an array.

            based on the counters you set another check that checks for how many in the array are set to 1, or 2, or 3, or 4... that way you can determine if you have pairs, 3 of a kind or 4 of a kind.

            Now my example is probably a really poor example of setup... but its been two years since I have coded anything in C and honestly I wasn't too great at it back then either.

            I hope it sparks some ideas though.

            P.S. the assigned number from 1-4 is for suite for comparison for straights and flushes... etc etc... but you probably guessed that from the beginning.

            AMD Phenom 9650, 8GB, 4x1TB, 2x22 DVD-RW, 2x9600GT, 23.6' ASUS, Vista Ultimate
            AMD X2 7750, 4GB, 1x1TB 2x500, 1x22 DVD-RW, 1x8500GT, 22" Acer, OS X 10.5.8
            Acer 6930G, T6400, 4GB, 500GB, 16", Vista Premium
            Lenovo Ideapad S10e, 2GB, 500GB, 10", OS X 10.5.8

            Comment

            Working...
            X