Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 5th, 2005, 5:11 PM   #1
takumi8374
Newbie
 
Join Date: May 2005
Posts: 6
Rep Power: 0 takumi8374 is on a distinguished road
can som1 help?

#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
takumi8374 is offline   Reply With Quote
Old May 5th, 2005, 5:26 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Loop through and check one against the other. It works kinda like a bubble sort, really.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 6th, 2005, 4:04 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
just lots of comparison to be done i think.

Or you could just have a 3 digit code for each card (first digit is suit and the next 2 are number of card and the comparison would be faster)
Berto is offline   Reply With Quote
Old May 6th, 2005, 6:47 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Hell, use hex and make it two digits.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 6th, 2005, 6:55 PM   #5
takumi8374
Newbie
 
Join Date: May 2005
Posts: 6
Rep Power: 0 takumi8374 is on a distinguished road
revised prog

#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
takumi8374 is offline   Reply With Quote
Old May 8th, 2005, 12:47 PM   #6
takumi8374
Newbie
 
Join Date: May 2005
Posts: 6
Rep Power: 0 takumi8374 is on a distinguished road
error C2084: function 'void deal(const int (*)[13],const char ** ,const char ** )' already has a body

warning C4028: formal parameter 1 different from declaration

these are the 2 errors i got
takumi8374 is offline   Reply With Quote
Old May 9th, 2005, 7:35 AM   #7
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 5 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
What are you using to compile? I don't get those errors. The only error I get involves the use of swap() under void cardQuality(). I changed from upper to lower case 's', and that eliminated one problem. But it appears it's not being used properly in this case. I'm looking it up and I'll post anymore info I find. I'm using Dev C++, btw.
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old May 9th, 2005, 8:00 AM   #8
lostcauz
Hobbyist Programmer
 
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 5 lostcauz is on a distinguished road
You have 2 deal functions.
void deal( const int wDeck[][ 13 ], const char *wFace[], const char *wSuit[] )
void deal(int pokerHand[][2], const char *suit1[], const char *face1[])
__________________
-- lostcauz

Stepped in what?...
Behind whose barn?...
I didn't even know they had a cow!
lostcauz is offline   Reply With Quote
Old May 9th, 2005, 7:36 PM   #9
takumi8374
Newbie
 
Join Date: May 2005
Posts: 6
Rep Power: 0 takumi8374 is on a distinguished road
to peace_of_mind: the compiler im using is microsoft visual studio.net 2003
takumi8374 is offline   Reply With Quote
Old May 10th, 2005, 3:48 AM   #10
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
You can have 2 functions of the same name as long as the parameters to pass are different .....
Berto is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:29 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC