Thread: poker game yooo

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

    poker game yooo

    Okay this is a lil game i am trying to make..
    Code:
     /***********************************************************
      *
      *   Program:    Poker Game
      *   Created:    09/12/02 03:38:AM
      *   Author:     Karan Sandhu
      *   Requested:
      *   Comments:   A small and simple poker game.
      *
      ************************************************************/
    
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define NUM_SUITS   4
    #define NUM_FACES   13
    #define HAND_SIZE   5
    
    void shuffle( int deck[][ NUM_FACES ] );
    void deal( int deck[][ NUM_FACES ], int hand[], int hand_size );
    void showhand( const int hand[], int hand_size,
                    const char *suits[], const char *faces[] );
    void getPair( int hand[], int hand_size, const char *suits[] );
    void getPairFace( int hand[], int hand_size, const char *face[] );
    int getSuit( int Card );
    int getFace( int Card );
    
    int main() {
        const char *suit[ NUM_SUITS ] =
          { "Hearts", "Diamonds", "Clubs", "Spades" };
        const char *face[ NUM_FACES ] =
          { "Ace", "Deuce", "Three", "Four",
            "Five", "Six", "Seven", "Eight",
            "Nine", "Ten", "Jack", "Queen", "King" };
        int deck[ NUM_SUITS ][ NUM_FACES ] = { { 0 } };
        int hand[HAND_SIZE];
    
        srand( time( NULL ) );
    
        shuffle( deck );
    	deal( deck, hand, HAND_SIZE );
    	showhand( hand, HAND_SIZE, suit, face );
        getPair( hand, HAND_SIZE, suit );
    	printf ("\t");
    	getPairFace(hand, HAND_SIZE, face);
    
    	system("pause");
        return 0;
    }
    
    void shuffle( int wDeck[][ NUM_FACES ] ) {
        int row, column, card;
    
        for(card = 1; card <= NUM_FACES*NUM_SUITS; card++) {
            do {
                row = rand( ) % NUM_SUITS;
                column = rand( ) % NUM_FACES;
            } while(wDeck[ row ][ column ] != 0);
    
            wDeck[ row ][ column ] = card;
        }
    }
    
    void deal( int wDeck[][ NUM_FACES ], int hand[], int hand_size ) {
        int card, row, column;
        for(card = 0; card < hand_size; card++) {
            do {
                row = rand( ) % NUM_SUITS;
                column = rand( ) % NUM_FACES;
            } while(wDeck[ row ][ column ] == 0);
    		hand[card] = wDeck[ row ][ column ];
    
    		wDeck[ row ][ column ] = 0; /* this card has been dealt */
        }
    }
    
    void showhand( const int hand[], int hand_size,
                    const char *suits[], const char *faces[] ) {
        int card, suit, face;
        for(card = 0 ; card < hand_size ; card++) {
            suit = getSuit( hand[card] );
            face = getFace( hand[card] );
    	    printf( "%5s of %-8s%c",
                faces[ face ], suits[ suit ],
                card % 2 == 0 ? '\n' : '\t' );
        }
    }
    
    void getPair( int hand[], int hand_size, const char *suits[] ) {
        int cnt_main, cnt_sub;
        int s1, s2;
    	int storeS[5] = {0};
    	int store[5] = {0};
    	int store1[5] = {0};
    
    
        for(cnt_main =0; cnt_main < hand_size; cnt_main++) {
            for(cnt_sub =cnt_main+1; cnt_sub < hand_size; cnt_sub++) {
                s1 = getSuit( hand[cnt_main] );
                s2 = getSuit( hand[cnt_sub] );
    				++store1[s1];
          		if (store1[s1] == 12 )
    				printf ("Congrat's man you got a flush\n");
    
    		   		++storeS[s1];
    		    if((s1 == s2) && (store[s1] == 0 || storeS[s1] == 6 ))
    			{
    				printf( "You have a pair of %s\n", suits[s1] );
    				++store[s1];
    			}
    
            }
    
        }
    }
    void getPairFace ( int hand[], int hand_size, const char *face[] ){
    	int cnt_main, cnt_sub;
    	int s1, s2;
    	int store[13] = {0};
    
    	for ( cnt_main = 0; cnt_main < hand_size; cnt_main++ )
    	{
    		for ( cnt_sub = cnt_main+1; cnt_sub < hand_size; cnt_sub++ )
    		{
    			s1 = getFace ( hand[cnt_main] );
    			s2 = getFace ( hand[cnt_sub] );
    			if (s1 == s2)
    			{
    				++store[s1];
    				if ( store[s1] == 3 )
    					printf ("You have three %s\n", face[s1]);
    				else if ( store[s1] == 4 )
    					printf ("You have four %s\n", face[s1]);
    				else if ( store[s1] == 5 )
    					printf( "You have a Straight\n" );
    
    
    		    }
      		}
    	}
    }
    
    int getSuit( int Card ) {
        return ( Card-1 )/NUM_FACES;
    }
    int getFace( int Card ) {
        return ( Card-1 )%NUM_FACES;
    }
    Okay the first thing i want you guys to check if my programm has any bugs! .So well i want to make another hand ..that means i want to display another 5 cards ... and after that compaire both of the hand which one is better ...The main stuff is the secound hand ..How to display another 5 cards and store it in a different varaible???...
    thanks alot

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    I didn't check for bugs but about the second hand.

    Just declare another one
    int hand2[HAND_SIZE];
    And pass it in to the relevant functions. Easy as that.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>How to display another 5 cards and store it in a different varaible???...
    Without thinking about it too hard, I'd guess you need to change this:
    >int hand[HAND_SIZE];
    to something like this:
    >int hand[HAND_SIZE][NUM_HANDS];
    or
    >>int hand[NUM_HANDS][HAND_SIZE];

    Then, just pass one of the hands to the existing functions to do the work.

    (Haven't looked for bugs)
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

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

    thanks hammer

    Code:
    /***********************************************************
      *
      *   Program:    Poker Game
      *   Created:    09/12/02 03:38:AM
      *   Author:     Karan Sandhu
      *   Requested:
      *   Comments:   A small and simple poker game.
      *
      ************************************************************/
    
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define NUM_SUITS   4
    #define NUM_FACES   13
    #define HAND_SIZE   5
    #define NUM_HAND 	2
    
    void shuffle( int deck[][ NUM_FACES ] );
    void deal( int deck[][ NUM_FACES ], int hand[][HAND_SIZE], int hand_size );
    void showhand( const int hand[][HAND_SIZE], int hand_size,
                    const char *suits[], const char *faces[] );
    void getPair( int hand[][HAND_SIZE], int hand_size, const char *suits[] );
    void getPairFace( int hand[][HAND_SIZE], int hand_size, const char *face[] );
    int getSuit( int Card );
    int getFace( int Card );
    
    int main() {
        const char *suit[ NUM_SUITS ] =
          { "Hearts", "Diamonds", "Clubs", "Spades" };
        const char *face[ NUM_FACES ] =
          { "Ace", "Deuce", "Three", "Four",
            "Five", "Six", "Seven", "Eight",
            "Nine", "Ten", "Jack", "Queen", "King" };
        int deck[ NUM_SUITS ][ NUM_FACES ] = { { 0 } };
        int hand[NUM_HAND][HAND_SIZE];
    
        srand( time( NULL ) );
    
        shuffle( deck );
    	deal( deck, hand, HAND_SIZE );
    	showhand( hand, HAND_SIZE, suit, face );
        getPair( hand, HAND_SIZE, suit );
    	getPairFace(hand, HAND_SIZE, face);
    
    	system("pause");
        return 0;
    }
    
    void shuffle( int wDeck[][ NUM_FACES ] ) {
        int row, column, card;
    
        for(card = 1; card <= NUM_FACES*NUM_SUITS; card++) {
            do {
                row = rand( ) % NUM_SUITS;
                column = rand( ) % NUM_FACES;
            } while(wDeck[ row ][ column ] != 0);
    
            wDeck[ row ][ column ] = card;
        }
    }
    
    void deal( int wDeck[][ NUM_FACES ], int hand[][HAND_SIZE], int hand_size ) {
        int card, row, column, hand_num;
    
    for (hand_num =0; hand_num <2; hand_num++ )
    {
        for(card = 0; card < hand_size; card++) {
            do {
                row = rand( ) % NUM_SUITS;
                column = rand( ) % NUM_FACES;
            } while(wDeck[ row ][ column ] == 0);
    		hand[hand_num][card] = wDeck[ row ][ column ];
    
    		wDeck[ row ][ column ] = 0; /* this card has been dealt */
        }
    }
    }
    
    void showhand( const int hand[][HAND_SIZE], int hand_size,
                    const char *suits[], const char *faces[] ) {
        int card, suit, face, hand_num;
    for ( hand_num =0; hand_num < 2; hand_num++ )
    {
        for(card = 0 ; card < hand_size ; card++) {
            suit = getSuit( hand[hand_num][card] );
            face = getFace( hand[hand_num][card] );
    	if ( hand_num == 1)
    		printf ("\n\t");
    	else if (hand_num == 0)
    		printf("\n");
    
    
    	    printf( "%5s of %-8s",
                faces[ face ], suits[ suit ] );
    	}
    }
    }
    
    void getPair( int hand[][HAND_SIZE], int hand_size, const char *suits[] ) {
        int cnt_main, cnt_sub, hand_num;
        int s1, s2;
    	int storeS[5] = {0};
    	int store[5] = {0};
    	int store1[5] = {0};
    
    for ( hand_num =0; hand_num < 2; hand_num++ )
    {
        for(cnt_main =0; cnt_main < hand_size; cnt_main++)
    	 {
            for(cnt_sub =cnt_main+1; cnt_sub < hand_size; cnt_sub++)
    		{
                s1 = getSuit( hand[hand_num][cnt_main] );
                s2 = getSuit( hand[hand_num][cnt_sub] );
    				++store1[s1];
          		if (store1[s1] == 12 )
    				printf ("Congrat's man you got a flush\n");
    
    		   	++storeS[s1];
    		    if((s1 == s2) && (store[s1] == 0 || storeS[s1] == 6 ))
    			{
    				printf( "You have a pair of %s\n", suits[s1] );
    				++store[s1];
    			}
    
            }
    
        }
    }
    }
    void getPairFace ( int hand[][HAND_SIZE], int hand_size, const char *face[] ){
    	int cnt_main, cnt_sub, hand_num;
    	int s1, s2;
    	int store[13] = {0};
    
    for ( hand_num =0; hand_num < 2; hand_num++ )
    {
    	for ( cnt_main = 0; cnt_main < hand_size; cnt_main++ )
    	{
    		for ( cnt_sub = cnt_main+1; cnt_sub < hand_size; cnt_sub++ )
    		{
    			s1 = getFace ( hand[hand_num][cnt_main] );
    			s2 = getFace ( hand[hand_num][cnt_sub] );
    			if (s1 == s2)
    			{
    				++store[s1];
    				if ( store[s1] == 3 )
    					printf ("You have three %s\n", face[s1]);
    				else if ( store[s1] == 4 )
    					printf ("You have four %s\n", face[s1]);
    				else if ( store[s1] == 5 )
    					printf( "You have a Straight\n" );
    
    
    		    }
      		}
    	}
    }
    }
    
    int getSuit( int Card ) {
        return ( Card-1 )/NUM_FACES;
    }
    int getFace( int Card ) {
        return ( Card-1 )%NUM_FACES;
    }
    After a while i made the second hand ..well cant print it in a proper format ..like
    Code:
    hand 1                           hand 2
    
    ace of Spades                five of hearts  
    two of Diamonds            king of diamonds
    
    etc..
    Well i havce created the second hand now i have to make compairisions between hand 1 and hand 2 . Oh and yeah hammer best of luck just a week left ..
    Thanks alot

    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 ???

  5. #5
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    And yeah do check for bugs ... and if u guys have a better way or if i have used any bad programming style then plZ do let me 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 ???

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

    my code is almost done

    Okay from my previous post non of u guys have help me out wiht the arrangement of the hand's.. okay here is my code
    Code:
     /***********************************************************
      *
      *   Program:    Poker Game
      *   Created:    09/12/02 03:38:AM
      *   Author:     Karan Sandhu
      *   Requested:
      *   Comments:   A small and simple poker game.
      *
      ************************************************************/
    
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    
    #define NUM_SUITS   4
    #define NUM_FACES   13
    #define HAND_SIZE   5
    #define NUM_HAND 	2
    #define POINT_SIZE	2
    
    void shuffle( int deck[][ NUM_FACES ] );
    void deal( int deck[][ NUM_FACES ], int hand[][HAND_SIZE], int hand_size );
    void showhand( const int hand[][HAND_SIZE], int hand_size,
                    const char *suits[], const char *faces[] );
    void getPair( int hand[][HAND_SIZE], int hand_size, const char *suits[], int point[] );
    void getPairFace( int hand[][HAND_SIZE], int hand_size, const char *face[], int point[] );
    int getSuit( int Card );
    int getFace( int Card );
    void winner (int point[]);
    
    int main()
    {
        const char *suit[ NUM_SUITS ] =
          { "Hearts", "Diamonds", "Clubs", "Spades" };
        const char *face[ NUM_FACES ] =
          { "Ace", "Deuce", "Three", "Four",
            "Five", "Six", "Seven", "Eight",
            "Nine", "Ten", "Jack", "Queen", "King" };
        int deck[ NUM_SUITS ][ NUM_FACES ] = { { 0 } };
        int hand[NUM_HAND][HAND_SIZE];
    	int point[POINT_SIZE] = {0};
    
        srand( time( NULL ) );
    
    	printf( "--------PKœR--------\n" );
    
         printf("©---------ª               ©---------ª\n"
    			"|       |               |       |\n"
    			"|         |               |         |\n"
    			"|        |               |        |\n"
    			"|         |               |         |\n"
    			"|       |   Presented   |       |\n"
    			"À---------Ù      By       À---------Ù\n");
    	 printf("            Datanjector             \n");
    	 printf("©---------ª               ©---------ª\n"
    			"|       |               |       |\n"
    			"|         |               |         |\n"
    			"|        |               |        |\n"
    			"|         |               |         |\n"
    			"|       |               |       |\n"
    			"À---------Ù               À---------Ù\n");
        printf ("Press <return> to continue with the game.....");
    	getchar();
       	system("cls");
        shuffle( deck );
    	deal( deck, hand, HAND_SIZE );
    	showhand( hand, HAND_SIZE, suit, face );
        getPair( hand, HAND_SIZE, suit, point );
    	getPairFace(hand, HAND_SIZE, face, point );
    	puts(" ");
    	winner ( point );
    
    	system("pause");
        return 0;
    }
    
    void shuffle( int wDeck[][ NUM_FACES ] )
     {
        int row, column, card;
    
        for(card = 1; card <= NUM_FACES*NUM_SUITS; card++) {
            do {
                row = rand( ) % NUM_SUITS;
                column = rand( ) % NUM_FACES;
            } while(wDeck[ row ][ column ] != 0);
    
            wDeck[ row ][ column ] = card;
        }
    }
    
    void deal( int wDeck[][ NUM_FACES ], int hand[][HAND_SIZE], int hand_size )
    {
        int card, row, column, hand_num;
    
    for (hand_num =0; hand_num <2; hand_num++ )
    {
        for(card = 0; card < hand_size; card++) {
            do {
                row = rand( ) % NUM_SUITS;
                column = rand( ) % NUM_FACES;
            } while(wDeck[ row ][ column ] == 0);
    		hand[hand_num][card] = wDeck[ row ][ column ];
    
    		wDeck[ row ][ column ] = 0; /* this card has been dealt */
        }
    }
    }
    
    void showhand( const int hand[][HAND_SIZE], int hand_size,
                    const char *suits[], const char *faces[] )
    {
        int card, suit, face, hand_num;
    
    for ( hand_num =0; hand_num < 2; hand_num++ )
    {
        for(card = 0 ; card < hand_size ; card++) {
            suit = getSuit( hand[hand_num][card] );
            face = getFace( hand[hand_num][card] );
    
    	 printf( "%5s of %-8s%c",
                faces[ face ], suits[ suit ], '\n'  );
    
    	}    printf ("\n");
    }
    }
    
    void getPair( int hand[][HAND_SIZE], int hand_size,
    			 const char *suits[], int point[] )
     {
        int cnt_main, hand_num;
        int s1;
       	int store[2][5] = {0};
    
    
    for ( hand_num =0; hand_num < 2; hand_num++ )
    {
        for(cnt_main =0; cnt_main < hand_size; cnt_main++)
    	 {
                s1 = getSuit( hand[hand_num][cnt_main] );
    
    			++store[hand_num][s1];
    
    			if ( store[hand_num][s1] == 2 )
    			{
    				printf ("You have a pair of %s\n", suits[s1]);
    				++point[hand_num];
    			}
    			else if ( store[hand_num][s1] == 4 )
    			{
    				printf( "And another pairs of %s\n", suits[s1] );
    			   	point[hand_num] += 2;
    			}
    			else if ( store[hand_num][s1] == 5)
    			{
    				printf( "Congatulation you got a flush" );
    				point[hand_num] += 5;
    			}
    
    
    
    	 }
       				printf ("\n");
    
    
    }
    
    }
    void getPairFace ( int hand[][HAND_SIZE], int hand_size,
    					const char *face[], int point[] )
    {
    	int cnt_main, hand_num;
    	int s1;
    	int store[2][13] = {0};
    
    for ( hand_num =0; hand_num < 2; hand_num++ )
    {
    	for ( cnt_main = 0; cnt_main < hand_size; cnt_main++ )
    	{
    			s1 = getFace ( hand[hand_num][cnt_main] );
    			++store[hand_num][s1];
    
    				if ( store[hand_num][s1] == 3 )
    				{
    					printf ("You have three %s\n", face[s1]);
    					point[hand_num] += 3;
    				}
    				else if ( store[hand_num][s1] == 4 )
    				{
    					printf ("You have four %s\n", face[s1]);
    					point[hand_num] += 4;
    				}
    				else if ( store[hand_num][s1] == 5 )
    				{
    					printf( "You have a Straight\n" );
    					point[hand_num] += 10;
    				}
    
    		    }
    
    	}
    }
    
    
    int getSuit( int Card ) {
        return ( Card-1 )/NUM_FACES;
    }
    int getFace( int Card ) {
        return ( Card-1 )%NUM_FACES;
    }
    
    void winner (int point[])
    {
    	if ( point[0] > point[1] )
    		printf("\nHand 1 wins!!\n");
    	else if ( point[0] < point[1] )
    		printf("\nHand 2 wins!!\n");
    	else
    		printf ("\nIts a Draw!!\n");
    }
    Okay so plzz help me out with thew arrangement of the hand ..
    So now i have to modify the programm to do :-

    Modify the programm so that it can simulate the dealer.The dealer's five-card hand is dealt "face down" so the player cannot c it.The programm should then evaluate the dealer's hand and, based on the quality of the hand, the dealer should draw one, two, or three more cards to replace the corresponding number unneeded cards in the original hand.The program should then reevaluate the dealer's hand...

    Okay i dont even have the slightest understanting of the question ...plzz if you guys can give me a easy to understand version of the above ....

    And its giving me a warning message like
    Code:
    70 c:\mydocu~1\untitl~1.c
     warning: passing arg 1 of `showhand' from incompatible pointer type
    Thanks alot

    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 ???

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    datainjector, don't panic! I'll try to have a look later on if no one else has helped you in the meantime.

    Can you expand on this:
    >Okay so plzz help me out with thew arrangement of the hand ..



    >Okay i dont even have the slightest understanting of the question
    Can you be more specific.... What part do you want help with.
    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, 09:59 PM
  2. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  5. world of problems with poker game
    By blight2c in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2002, 08:00 PM