Thread: Calculate the rank of poker game

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    3

    Angry Calculate the rank of poker game

    i've been thinking this problem many time,but didn't know how to do this. Need Some Help!

    The example are listed as follows

    largest
    Rank1 A A A A
    Rank2 A A A
    Rank3 A A + K K
    Rank4 A A
    Rank5 A

    smallest
    Rank1 2 2 2 2
    Rank2 2 2 2
    Rank3 2 2 + 3 3
    Rank4 2 2
    Rank5 2

    i've completed to compile how to shuffle and deal the cards,
    now is also owe this one, are there any helpers to help me?
    Thanks a lot.

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    anyone can help me?

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    It's not totally clear what you want to do. If this is actually 4-card poker (you do know it is normally 5?), a straight or flush will beat three of a kind, and three 2's beat 2 pairs, even if the pairs are aces and kings. So you should compare on the basis of hands first:

    Four card poker - Wikipedia, the free encyclopedia

    Use a function that checks for each hand in order and returns an enum value, eg:

    Code:
    enum {
        NOTHING,
        PAIR,
        TWO_PAIR,
        STRAIGHT,
    [...etc]
    };
    If there is a tie, then use the card values (eg, if both hands == NOTHING, you are looking for the "high card").
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    My code is posted as follows
    Maybe now is clearly what i want to say
    In my code,these 4players should be compared by the rank
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define  ARY_SIZE  52
    
    void bldPerm   (int randNos[]);
    void printData (int data[], int size, int lineSize);
    
    int main (void)
    {
    
        int randNos [ARY_SIZE];
        char answer,other;
        int data;
    
        do{
        printf("Begin shuffing cards.\n");
    
        bldPerm   (randNos);
        printData (randNos, 21, 4 );
    
        printf("\nPlease enter 'Y'or'y' to contiue.\n");
        scanf("%c%c",&answer,&other);
    
    }while(answer=='Y' || answer=='y');
    
    
        return 0;
    }
    
    
    void bldPerm (int randNos[])
    {
    
        int oneRandNo;
        int haveRand[ARY_SIZE] = {0};
        int i;
        int total=0;
    
        srand(time(NULL));
    
    
        for (i = 1; i < ARY_SIZE; i++)
        {
             do
             {
                oneRandNo = (rand() % (ARY_SIZE-1) ) +1;
                total++;
             } while (haveRand[oneRandNo] == 1);
    
             haveRand[oneRandNo] = 1;
             randNos[i] = oneRandNo;
    
        }
        printf("%c : %c : %c :%c \n",6,3,5,4);
        return;
    }
    
    
    void printData (int data[], int size, int lineSize)
    {
    
        int numPrinted = 0;
        int i;
        int pttn, card;
        int sP1,sP2,sP3,sP4;
    
    
    
        printf("\n");
        for ( i = 1; i < lineSize+1; i++)
            printf(" Player%d \t", i);
        printf("\n");
    
        for ( i = 1; i < lineSize+1; i++)
            printf("=========\t");
        printf("\n");
    
    
        for ( i = 1; i < size; i++)
        {
            numPrinted++;
            pttn = data[i]/13;
            card = data[i]%13+1;
    
        switch(card)
        {
            case 1:printf(" A of");
            break;
            case 11:printf(" J of");
            break;
            case 12:printf(" Q of");
            break;
            case 13:printf(" K of");
            break;
            default:printf("%2d of",card);
            break;
        }
        switch(pttn)
        {
            case 0:printf(" %c\t\t",6);
                break;
            case 1:printf(" %c\t\t",3);
                break;
            case 2:printf(" %c\t\t",5);
                break;
            case 3:printf(" %c\t\t",4);
                break;
        }
    
            if (numPrinted >= lineSize)
            {
                printf("\n");
                numPrinted = 0;
            }
        }
    
        /*;*/sP1=data[1]%13+1 + data[5]%13+1 + data[9]%13+1 + data[13]%13+1 + data[17]%13+1;
        sP2=data[2]%13+1 + data[6]%13+1 + data[10]%13+1 + data[14]%13+1 + data[18]%13+1;
        sP3=data[3]%13+1 + data[7]%13+1 + data[11]%13+1 + data[15]%13+1 + data[19]%13+1;
        sP4=data[4]%13+1 + data[8]%13+1 + data[12]%13+1 + data[16]%13+1 + data[20]%13+1;
    
    
        for ( i = 1; i < lineSize+1; i++)
        printf("=========\t");
        printf("\n");
    
        int Sum[]={0,sP1,sP2,sP3,sP4};
    
        for( i = 1; i < lineSize+1; i++)
        {
        printf("  T%d=%d  \t", i, Sum[i]);
        }
    
         if ((Sum[1] > Sum[2]) && (Sum[1] > Sum[3]) && (Sum[1] > Sum[4]))
            printf("\n\nPlayer 1 has win.\n");
        else if ((Sum[2] > Sum[1]) && (Sum[2] > Sum[3]) && (Sum[2] > Sum[4]))
            printf("\n\nPlayer 2 has win.\n");
    
        else if ((Sum[3] > Sum[1]) && (Sum[3] > Sum[2]) && (Sum[3] > Sum[4]))
            printf("\n\nPlayer 3 has win.\n");
    
        else if ((Sum[4] > Sum[1]) && (Sum[4] > Sum[2]) && (Sum[4] > Sum[3]))
            printf("\n\nPlayer 4 has win.\n");
    
        else if ((Sum[1] == Sum[2]) && (Sum[1]== Sum[3]) &&  (Sum[1]== Sum[4]))
            printf("\n\nThe game is drawn.");
        else if ((Sum[2] == Sum[1]) && (Sum[2]== Sum[3]) &&  (Sum[2]== Sum[4]))
            printf("\n\nThe game is drawn.");
        else if ((Sum[3] == Sum[1]) && (Sum[3]== Sum[2]) &&  (Sum[3]== Sum[4]))
            printf("\n\nThe game is drawn.");
        else if ((Sum[4] == Sum[1]) && (Sum[4]== Sum[2]) &&  (Sum[4]== Sum[3]))
            printf("\n\nThe game is drawn.");
    
    return ;
    }
    i need your help,thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Poker Game need help...
    By boyracer88 in forum Game Programming
    Replies: 1
    Last Post: 11-25-2005, 01:32 PM
  2. Poker Game
    By egomaster69 in forum C Programming
    Replies: 18
    Last Post: 01-03-2005, 06:24 PM
  3. poker game
    By b00l34n in forum Game Programming
    Replies: 14
    Last Post: 01-03-2005, 12:21 PM
  4. Poker Game
    By Smiley**123 in forum Game Programming
    Replies: 6
    Last Post: 12-14-2003, 09:48 AM
  5. poker game help
    By datainjector in forum C Programming
    Replies: 5
    Last Post: 09-06-2002, 07:31 AM