poker game help

This is a discussion on poker game help within the C Programming forums, part of the General Programming Boards category; hi guys sup.... well i have to make this poker game right let me first post the code.. Code: #include ...

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    Unhappy poker game help

    hi guys sup....
    well i have to make this poker game right let me first post the code..
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    void shuffle( int [][ 13 ] );
    void deal( const int [][ 13 ], const char *[], const char *[] );
    
    int main()
    {
       const char *suit[ 4 ] =  
          { "Hearts", "Diamonds", "Clubs", "Spades" };
       const char *face[ 13 ] = 
          { "Ace", "Deuce", "Three", "Four",
            "Five", "Six", "Seven", "Eight",
            "Nine", "Ten", "Jack", "Queen", "King" };
       int deck[ 4 ][ 13 ] = { 0 };
    
       srand( time( 0 ) );
    
       shuffle( deck );
       deal( deck, face, suit );
    
       return 0;
    }
    
    void shuffle( int wDeck[][ 13 ] )
    {
       int row, column, card;
    
       for ( card = 1; card <= 52; card++ ) {
          do {
             row = rand() % 4;
             column = rand() % 13;
          } while( wDeck[ row ][ column ] != 0 );
    
          wDeck[ row ][ column ] = card;
       }
    }
    
    void deal( const int wDeck[][ 13 ], const char *wFace[],
               const char *wSuit[] )
    {
       int card, row, column;
    
       for ( card = 1; card <= 52; card++ )
    
          for ( row = 0; row <= 3; row++ )
    
             for ( column = 0; column <= 12; column++ )
    
                if ( wDeck[ row ][ column ] == card )
                   printf( "%5s of %-8s%c",
    			            wFace[ column ], wSuit[ row ],
    						card % 2 == 0 ? '\n' : '\t' );
    }
    okay .So i have to modify the programm so it should show only 5 cards ..i can do that its easy but the problem is the question says i should print out if there is a pair of suits or more... okay i tried a brute force method but it dint work let me give u an example...
    Code:
    for ( cnt_main =0; cnt_main <=4; cnt_main++ )
    
    	for ( cnt_sub =0; cnt_sub <=4; cnt_sub++ )
    		if  ( suit[cnt_main] == suit[cnt_sub] )
    		printf ("You have a pair of %s", suit );
    but the problem is suit[main] is one and suit[sub] is one it will say its a pair right....well is it possible to use continue for it ????....if u guys have a better way i would like to know...thanks

    DaIn
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  2. #2
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    ????

    Originally posted by Salem
    So you have a value in the range 1..52 which represents each possible card

    For some card, you do this
    int suit = (card - 1) / 13;
    int rank = (card - 1) % 13;

    You calculate this for a pair of cards, so you have say
    int suit1 = (card1 - 1) / 13;
    int rank1 = (card1 - 1) % 13;
    int suit2 = (card2 - 1) / 13;
    int rank2 = (card2 - 1) % 13;

    Then you do
    if ( suit1 == suit2 ) {
    }
    hey salem i am still confused i how would i use the algorithm u gave ... i have alil hunch about how it works but how to imply i ... thanks alot

    DaIn

  3. #3
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Perhaps you should write a more efficient shuffling algorithm? It seems like it may take many loops to insert the last few cards when using random values. Perhaps you should lay out your entire deck in the array and then swap random cards a certain amount of times. What do you guys think?
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  4. #4
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    yooo

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    void shuffle( int [][ 13 ] );
    void deal( const int [][ 13 ], const char *[], const char *[] );
    
    int main()
    {
       const char *suit[ 4 ] =  
          { "Hearts", "Diamonds", "Clubs", "Spades" };
       const char *face[ 13 ] = 
          { "Ace", "Deuce", "Three", "Four",
            "Five", "Six", "Seven", "Eight",
            "Nine", "Ten", "Jack", "Queen", "King" };
       int deck[ 4 ][ 13 ] = { 0 };
    
       srand( time( 0 ) );
    
       shuffle( deck );
       deal( deck, face, suit );
    
       system ("pause");
       return 0;
    }
    
    void shuffle( int wDeck[][ 13 ] )
    {
       int row, column, card;
    
       for ( card = 1; card <= 52; card++ ) {
          do {
             row = rand() % 4;
             column = rand() % 13;
          } while( wDeck[ row ][ column ] != 0 );
    
          wDeck[ row ][ column ] = card;
       }
    }
    
    void deal( const int wDeck[][ 13 ], const char *wFace[],
               const char *wSuit[] )
    {
       int card, row, column;
       void getPair ( int[][5],int* );
       int getSuit ( int );
       for ( card = 1; card <= 5; card++ )
    
          for ( row = 0; row <= 3; row++ )
    
             for ( column = 0; column <= 12; column++ )
    
                if ( wDeck[ row ][ column ] == card )
                   printf( "%5s of %-8s%c",
    			            wFace[ column ], wSuit[ row ],
    						card % 2 == 0 ? '\n' : '\t' );
               printf( "\n" );
               getPair (wDeck , wSuit);
    }
    int getSuit ( int Card )
    {
        return ( Card-1)/13;
    }
    
    void getPair ( int wDeck[][5], int *pSuit )
    {
     int hand[5]={0};
     int cnt_main, cnt_sub;
     int s1, s2;
    
     for ( cnt_main = 0; cnt_main <= 4; cnt_main++ )
         hand[cnt_main] = wDeck[0][cnt_main];
    
     for ( cnt_main =0; cnt_main <= 4; cnt_main++ )
     {
         for ( cnt_sub =0; cnt_sub <= 4; cnt_sub++ )
    
         s1 = getSuit( hand[cnt_main] );
         s2 = getSuit( hand[cnt_sub] );
         if ( s1 == s2 )
            printf( "You have a pair of %s", pSuit[s1]);
      }
    }
    well i know ..i am not so good with pointers at the moment it will take some time ..might be after 6 or 7 questions..well this is my first question with pointers... ummm..Salem i am still nt sure about how ur algorithm work ..I went through it but my magic switch isnt on ..Well its giving me warning like

    Warning
    21 c:\mydocu~1\card_g~1.c
    warning: passing arg 1 of `deal' from incompatible pointer type
    58 c:\mydocu~1\card_g~1.c
    warning: passing arg 1 of `getPair' from incompatible pointer type
    58 c:\mydocu~1\card_g~1.c
    warning: passing arg 2 of `getPair' from incompatible pointer type

    Well i dont know what they mean a explanantion would help alot..and yeah is it my implimantation of pointer that are causing the warning or is it the functions...
    Thanks alot
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  5. #5
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    help

    did it to bring it to the top
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    - don't bump your threads

    Now
    In: main:
    int deck[ 4 ][ 13 ]
    deal( deck, face, suit );

    In: void deal( const int wDeck[][ 13 ], ....
    void getPair ( int[][5],int* );
    getPair (wDeck , wSuit);

    In: void getPair ( int wDeck[][5], int *pSuit )
    - You are changing the array sizes (13 to 5),
    - some are passed into one function as const, then onwards to a second function as non-const.

    That might be your problems, I haven't read it too carefully.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

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, 10:59 PM
  2. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 12:58 PM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 05:19 AM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-25-2002, 12:00 AM
  5. world of problems with poker game
    By blight2c in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2002, 09:00 PM

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