-
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
-
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.
-
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
-
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;
}
}