help modifying code

Discussion in 'C' started by JamC, Jul 29, 2007.

  1. JamC

    JamC New Member

    Joined:
    Jun 23, 2007
    Messages:
    8
    Likes Received:
    1
    Trophy Points:
    0
    I have a program evaluating a straight hand in poker: Here is my code:
    Code:
    int numInRank[14];
    
    cin.get(rankCh);
        switch (toupper(rankCh))
         {
          case '-1':            exit(0);
          case '?':           rank = 0; break;
          case 'A':          rank = 1; break;
          case '2':           rank = 2; break;
          case '3':           rank = 3; break;
          case '4':           rank = 4; break;
          case '5':           rank = 5; break;
          case '6':           rank = 6; break;
          case '7':           rank = 7; break;
          case '8':           rank = 8; break;
          case '9':           rank = 9; break;
          case 'T':           rank = 10; break;
          case 'J':           rank = 11; break;
          case 'Q':          rank = 12; break;
          case 'K':          rank = 13; break;
    
    bool isStraight(int numInRank[]){
        int count = 0;
        for(int i = 1; i  < 14; i++){
            if(numInRank[i] != 0){
                count++;
                if(i == 13 && numInRank[1] != 0) count++;
            }else{
                count = 0;
            }
            if(count == 5) return true;
        }
        return false;
    }
    I would like to modify the above code to handle A high and A low straights- I sized my array to 14 instead of 13 to hold both...
    Any suggestions...
     
    Last edited by a moderator: Jul 29, 2007
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    The way I do it, for a 5-card hand, is to ensure that there are no duplicates, find the minimum and maximum values, and see if there is a difference of 4 between max and min. If it doesn't produce a straight, and min is 1, I reassign the A to its high value, set it as max, find the new min, and do it again.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice