poker full house!!

This is a discussion on poker full house!! within the C++ Programming forums, part of the General Programming Boards category; I want to print out all 3744 possible poker full houses. Right now I am just assigning cards to be ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    27

    poker full house!!

    I want to print out all 3744 possible poker full houses. Right now I am just assigning cards to be numbers. I'll deal with that later. But here is what I have so far and I'm just getting bad data.

    Code:
    int main()
    {
    int array[] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; // if there is a pair or
                                                                   // 3 of  a kind it will add 1
                                                                   // to the appropriate space
    int count = 0; //  if count is 2 then there is a full house
    
      for(int i = 0; i <= 51; i++)
      {
        for(int j = i + 1; j <= 51; j++)
        {
          for(int k = j + 1; k <= 51; k++)
          {
            for(int l = k + 1; l <= 51; l++)
            {
             for(int m = l + 1; m <= 51; m++)
             {
               int i_i = i % 12;   // this is adding up pairs and 3 of a kind
               array[i_i] += 1;
               int j_j = j % 12;
               array[j_j] += 1;
               int k_k = k % 12;
               array[k_k] += 1;
               int l_l = l % 12;
               array[l_l] += 1;
               int m_m = m % 12;
               array[m_m] += 1;
    
               for(int z = 0; z <= 12; z++)
               {
                    if(array[z] == 2) count += 1;
                    if(array[z] == 3) count += 1;
    
                  if(count == 2)
                  {
                   cout <<i<<" "<<j<<" "<<k<<" "<<l<<" "<<m<<endl;
                  }
               }
             }
            }
          }
        }
                // this could very easily be wrong but I don't know when and
                // where to reset things
                  for(int q = 0; q <= 12; ++q)
                    {
                      array[q] = 0;
                    }
                    count = 0;
    
      }
      return 0;
    }
    Anybody out there with any advice??
    Last edited by noodle24; 05-19-2006 at 04:20 PM.

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Conventially, if you want to count from 0 to 99 in C or C++, one writes
    Code:
    for (int i = 0; i < 100; ++i)
    instead of
    Code:
    for (int i = 0; i <= 99; ++i)
    You want to take the numbers mod 13 rather than 12.

    This method for detecting a full house is buggy.
    Consider
    2 Aces
    2 Kings
    1 Jack

    Code:
               for(int z = 0; z <= 12; z++)
               {
                    if(array[z] == 2) count += 1;
                    if(array[z] == 3) count += 1;
    
                  if(count == 2)
                  {
                   cout <<i<<" "<<j<<" "<<k<<" "<<l<<" "<<m<<endl;
                  }
               }
    array[z] == 2 twice, so count becomes 2, but you don't actually have a full house.

    You should reset your counters right after you detect a full house. You do 5 increments, then you want to cancel those increments out immediately so that you don't start "accumulating" lots and lots of cards in your counter.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,035
    You only need one variable instead of all those i_i, j_j, k_k ext. Just reasign it each time.

    Also in order to include all the combinations, you need to also track card suit.
    Last edited by King Mir; 05-19-2006 at 09:23 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help!For poker game simulation
    By tx1988 in forum C++ Programming
    Replies: 24
    Last Post: 05-25-2007, 09:59 PM
  2. Counting days
    By TheShaggmeister in forum C++ Programming
    Replies: 5
    Last Post: 07-17-2003, 10:29 AM
  3. hashing help
    By alokin in forum C Programming
    Replies: 17
    Last Post: 10-28-2002, 05:33 PM

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