Can some1 help me plz

This is a discussion on Can some1 help me plz within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> #include <time.h> #define NUM_FACES 13 void shuffle( int wDeck[][ 13 ] ); void deal( const ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    5

    Can some1 help me plz

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define NUM_FACES   13
    
    void shuffle( int wDeck[][ 13 ] );
    void deal( const int wDeck[][ 13 ], const char *wFace[], 
               const char *wSuit[] );
    
    int getSuit( int Card );
    int getFace( int Card );
    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 };
    
       shuffle( deck );
       deal( deck, face, suit );
    
       return 0; 
    
    }
    
    
    void shuffle( int wDeck[][ 13 ] )
    {
       int row;    
       int column; 
       int card;   
    
      
       for ( card = 1; card <= 5; 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;   
       int row;    
       int column; 
    
       
       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' );
                } 
             
    		 } 
          } 
    
       } 
    
    }
    how can you check to see if the five cards that were deal does it contain a pair of the same numbers
    ex) 3 of spades, 4 of cloves, 5 of diamond, 3 of diamonds, king of spades,
    this should say it has a pairs of 3s

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Write a function called 'checkhand', pass it the hand, then loop through it comparing all of the possible outcomes. Start with the best, work downwards towards the lower hands.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    5

    revised code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define NUM_FACES 13
    
    void shuffle( int wDeck[][ 13 ] );
    void deal( const int wDeck[][ 13 ], const char *wFace[], 
               const char *wSuit[] );
    
    int getSuit( int Card );
    int getFace( int Card );
    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 };
    
       shuffle( deck );
       deal( deck, face, suit );
    
       return 0; 
    
    }
    
    
    void shuffle( int wDeck[][ 13 ] )
    {
       int row;    
       int column; 
       int card;
    
       for ( card = 1; card <= 5; 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;   
       int row;    
       int column; 
    
       
       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' );
                } 
             
    		 } 
          } 
    
       } 
    
    }
    void deal(int pokerHand[][2], const char *suit1[], const char *face1[])
    {
    	int a , b;
    
    	for ( a = 0 ; a <= 4; a++ ){
    		    b = 0;  
                
    			printf("%s", suit1[pokerHand[a][b]]);			
         		b = 1;
    			
    			printf("%s  ", face1[pokerHand[a][b]]);		
    	}
    	printf("\n");
    }
    
    void cardQuality( int playerHand [][2] ) {
    
    	int y,z; 
    	int positFace[5], positSuit[5];
    	int *fPtr = positFace, *sPtr = positSuit ; 
        int Facepass = 0;
    	int swap;
    	int Suitpass = 0 ;
    	int straight = 0;
    
    	for ( y = 0 ; y <= 4 ; y++ ){
    		z = 1 ;      
    		*fPtr = playerHand[y][z];
    		fPtr++ ;
    	}
    	for ( y = 0 ; y <= 4 ; y++ ){
    		z = 0 ;
    		*sPtr = playerHand[y][z];
    		sPtr++ ;
    	}
    	  
    	  for ( y = 0 ; y <= 3 ; y++ ) {		  
    		  for ( z = (y + 1); z <= 4 ; z++ ){
    			  if ( *(positFace + y ) == *(positFace + z ) ) {
    				  Facepass++;		  
    			  }
    		  }
    	  }
    	  for ( z = 0 ; z <= 3 ; z++ ){
    	  for (y = 0 ; y <= 3 ; y++ ){
    		  if ( positFace[y] > positFace[y+1] ) {
    			  Swap(&positFace[y],&positFace[y+1]);
    		  }
    	  }
    	  }
          for ( z = 0; z <= 3 ; z++ ){		  
    		if ( positFace[z] == positFace[z + 1] - 1  ){
    			straight++;		  
    		}
    	  }
    	  
    	  for ( z = 1; z <= 4 ; z++ ){
    		if ( *positSuit == *(positSuit + z ) ) {
    			Suitpass++;		  
    		}
    	  }  
    
    	  switch ( Facepass ){
    	  
    	  case 1 :
    		  printf("The poker hand contains a pair\n" );
    	  break ; 
    	  case 2 :
    		  printf("The poker hand contains two pair\n" );
    	  break;
    	  case 3 :
    		  printf("The poker hand contains three of a kind\n");
    	  break ;
    	  case 4:
    		  printf("The poker hand contains full house\n");
    	  break ;
    	  case 6: 
    		  printf("The poker hand contains four fo a kind\n");
    	  break ;
    	  default :
              if ( Suitpass == 4 && straight != 4) {
    				printf("The poker hand contains flush\n");
                     
    		  }
    		  if ( straight == 4 && Suitpass != 4) {
    		    	printf("The poker hand contains straight\n");
    		  }
    		  if ( straight == 4 && Suitpass == 4) {
    			    printf("The poker hand contains straight flush\n");
    		  }
    	  break;
    	  }
    
    }
    I dunno whats wrong but this won't run at all

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    I have not checked the semantics of your code. You have not included any comments whatsoever!
    Don't expect people to understand what your code does no matter how much experience you think
    they have.

    Idea:
    Have a structure called Card, and have the suit and face values as fields.
    Then write methods that manipulate these structs.

    eg.
    Code:
    // Don't use magic numbers. Use symbolic constants.
    #define CARDS_PER_HAND 5
    
    typedef struct tagCard
    {
    	int suit;
    	int faceValue;
    }Card;
    
    typedef struct tagHand
    {
    	struct tagCard cards[CARDS_PER_HAND];
    }Hand;
    Please read the comments which I have placed in your code.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define NUM_FACES 13
    
    void shuffle( int wDeck[][ 13 ] );
    void deal( const int wDeck[][ 13 ], const char *wFace[], const char *wSuit[] );
    
    int getSuit( int Card );
    int getFace( int Card );
    
    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 };
    
    	shuffle( deck );
    	deal( deck,  face, suit );
    
    	return 0;
    }
    
    void shuffle( int wDeck[][ 13 ] )
    {
    	int row;
    	int column;
    	int card;
    
    	for ( card = 1; card <= 5; 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;
    	int row;
    	int column;
    
    	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' );
    				}
    			}
    		}
    	}
    }
    
    // Why is this function called deal?? There's already a function called deal!
    void deal(int pokerHand[][2], const char *suit1[], const char *face1[])
    {
    	int a , b;
    
    	for ( a = 0 ; a <= 4; a++ )
    	{
    		// Why ??
    //		b = 0;
    //		printf("%s", suit1[pokerHand[a][b]]);
    //		b = 1;
    //		printf("%s  ", face1[pokerHand[a][b]]);
    
    		// Why not just say
    		printf("%s", suit1[pokerHand[a][0]]);
    		printf("%s  ", face1[pokerHand[a][1]]);
    	}
    	printf("\n");
    }
    
    void cardQuality( int playerHand [][2] )
    {
    	int y,z;
    	int positFace[5], positSuit[5];
    	int *fPtr = positFace,  *sPtr = positSuit ;
    	int Facepass = 0;
    	int swap;
    	int Suitpass = 0;
    	int straight = 0;
    
    	for ( y = 0 ; y <= 4 ; y++ )
    	{
    		// Why ??
    		// z = 1 ;
    		// *fPtr = playerHand[y][z];
    
    		// Why not just say
    		*fPtr = playerHand[y][1];
    
    		fPtr++;
    	}
    
    	for ( y = 0 ; y <= 4 ; y++ )
    	{
    		// Again, why ??
    		// z = 0 ;
    		// *sPtr = playerHand[y][z];
    
    		// Why not just say
    		*sPtr = playerHand[y][0];
    		sPtr++;
    	}
    
    	for ( y = 0 ; y <= 3 ; y++ )
    	{
    		for ( z = (y + 1); z <= 4 ; z++ )
    		{
    			if (*(positFace +   y ) == *(positFace + z ) )
    			{
    				Facepass++;
    			}
    		}
    	}
    
    	for ( z = 0 ; z <= 3 ; z++ )
    	{
    		for (y = 0 ; y <= 3 ; y++ )
    		{
    			if ( positFace[y] > positFace[y+1])
    			{
    				// There's no declaration for this function
    				Swap(&positFace[y],&positFace[y+1]);
    			}
    		}
    	}
    
    	for ( z = 0; z  <= 3 ; z++ )
    	{
    		if ( positFace[z]   == positFace[z + 1] - 1  )
    		{
    			straight++;
    		}
    	}
    
    	for (   z = 1; z <= 4 ; z++ )
    	{
    		if ( *positSuit == *(positSuit + z ) )
    		{
    			Suitpass++;
    		}
    	}
    
    	switch ( Facepass )
    	{
    	case 1 :	printf("The poker hand contains a pair\n" ); break ;
    	case 2 :	printf("The poker hand contains two pair\n" ); break;
    	case 3 :	printf("The poker hand contains three of a kind\n"); break ;
    	case 4 :	printf("The poker hand contains full house\n"); break ;
    	case 6 :	printf("The poker hand contains four fo a kind\n"); break ;
    	default : 
    			if ( Suitpass == 4 && straight != 4)
    			{
    				printf("The poker hand contains flush\n");
    			}
    			if ( straight == 4 && Suitpass != 4)
    			{
    				printf("The poker hand contains straight\n");
    			}
    			if ( straight == 4 && Suitpass == 4)
    			{
    				printf("The poker hand contains straight flush\n");
    			}
    			break;
    	}
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  3. plz help me with simple string comparison.
    By MegaManZZ in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2008, 12:11 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

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