My goal is to: Use the functions developed below to deal two five-card poker han
ID: 3634482 • Letter: M
Question
My goal is to:Use the functions developed below to deal two five-card poker hands, evaluate each hand, and determine which is the better hand.
Simulate the dealer. The dealer's five-card hand is dealt "face down" so the player cannot see it. The program 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 of unneeded cards in the original hand. The program should then re-evaluate the dealer's hand.
Make the program handle the dealer's five-card hand automatically. The player should be allowed to decide which cards of the player's hand to replace. The program should then evaluate both hands and determine who wins.
This is the code that I have so far and need help completing the rest:
Header:
#ifndef HEADER_H
#define HEADER_H
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void shuffle( int deck[][ 13 ] );
void deal(int deck[][ 13 ], int hand[][ 2 ], char *suit[], char *face[] );
void pair( int hand[][ 2 ], char *suit[], char *face[] );
void threeOfKind( int hand[][ 2 ], char *suit[], char *face[] );
void fourOfKind( int hand[][ 2 ], char *suit[], char *face[] );
void straightHand( int hand[][ 2 ], char *suit[], char *face[] );
void flushHand( int hand[][ 2 ], char *suit[], char *face[] );
#endif
Functions:
#include "header.h"
void shuffle( int deck[][ 13 ] )
{
int row;
int column;
int card;
for ( card = 1; card <= 52; card++ )
{
do
{
row = rand() % 4;
column = rand() % 13;
} while( deck[ row ][ column ] != 0 );
deck[ row ][ column ] = card;
}
}
void deal( int deck[][ 13 ], int hand[][ 2 ], char *suit[], char *face[] )
{
int c = 0;
int card, row, column;
printf( "Your hand is: " );
for ( card = 1; card < 6; card++ )
{
for ( row = 0; row <= 3; row++ )
{
for ( column = 0; column <= 12; column++ )
{
if ( deck[ row ][ column ] == card )
{
hand[c][0] = row;
hand[c][1] = column;
printf( "%5s of %-8s ", face[ column ], suit[ row ] );
++c;
}
}
}
}
printf( " " );
}
void pair( int hand[][ 2 ], char *suit[], char *face[] )
{
int counter[ 13 ] = { 0 };
int c, pair;
for ( c = 0; c < 5; c++ )
{
counter[ hand[ c ][ 1 ] ]++;
for ( pair = 0; pair < 13; pair++ )
{
if ( counter[ pair ] == 2 )
{
printf( "The hand contains a pair of %ss. ", face[ pair ] );
}
}
}
}
void threeOfKind( int hand[][ 2 ], char *suit[], char *face[] )
{
int counter[ 13 ] = { 0 };
int c, three;
for ( c = 0; c < 5; c++ )
{
counter[ hand[ c ][ 1 ] ]++;
for ( three = 0; three < 13; three++ )
{
if ( counter[ three ] == 3 )
{
printf( "The hand contains three %ss. ", face[ three ] );
}
}
}
}
void fourOfKind( int hand[][ 2 ], char *suit[], char *face[] )
{
int counter[ 13 ] = { 0 };
int c, four;
for ( c = 0; c < 5; c++ )
{
counter[ hand[ c ][ 1 ] ]++;
for ( four = 0; four < 13; four++ )
{
if ( counter[four ] == 4 )
{
printf( "The hand contains four %ss. ", face[ four ] );
}
}
}
}
void straightHand( int hand[][ 2 ], char *suit[], char *face[] )
{
int straight[ 5 ] = { 0 };
int temp;
int c, pass, comp;
/* copy column locations to sort */
for ( c = 0; c < 5; c++ )
{
straight[ c ] = hand[ c ][ 1 ];
for ( pass = 1; pass < 5; pass++ )
{
for ( comp = 0; comp < 4; comp++ )
{
if ( straight[ comp ] > straight[ comp + 1 ] )
{
temp = straight[ comp ];
straight[ comp ] = straight[ comp + 1 ];
straight[ comp + 1 ] = temp;
}
if ((straight[ 4 ] - 1) == straight[ 3 ]) && ((straight[ 3 ] - 1) == straight[ 2 ]) && ((straight[ 2 ] - 1) == straight 1 ]) && ((straight[ 1 ] - 1) == straight[ 0 ])
{
printf( "The hand contains a straight from %s to %s. ", face[ straight[ 0 ] ], face[ straight[ 4 ] ] );
}
}
}
}
void flushHand( int hand[][ 2 ], char *suit[], char *face[] )
{
int count[ 4 ] = { 0 };
int c, flush;
for ( c = 0; c < 5; c++ )
{
count[ hand[ c ][ 0 ] ]++;
for ( flush = 0; flush < 4; flush++ )
{
if ( count[ flush ] == 5 )
{
printf( "The hand contains a flush of %ss. ", suit[ flush ] );
}
}
}
}
Main:
#include "header.h"
int main()
{
char *suit[ 4 ] = { "Hearts", "Diamonds", "Clubs", "Spades" };
char *face[ 13 ] = { "Ace", "Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King" };
int deck[ 4 ][ 13 ];
int hand[ 5 ][ 2 ];
int row, column;
for ( row = 0; row <= 3; row++ )
{
for ( column = 0; column <= 12; column++ )
{
deck[ row ][ column ] = 0;
}
}
srand( time( NULL ) );
shuffle( deck );
deal( deck, hand, suit, face );
pair( hand, suit, face );
threeOfKind( hand, suit, face );
fourOfKind( hand, suit, face );
straightHand( hand, suit, face );
flushHand( hand, suit, face );
return 0;
}
Explanation / Answer
struct card{ string suite; int value; }; //Function prototypes: bool is_one_pair(card&); bool is_two_pair(card&); bool is_three_of_kind(card&); bool is_straight(card&); bool is_flush(card&); bool is_full_house(card&); bool is_four_of_kind(card&); bool is_straight_flush(card&); void high_card(card&); //create containers that will represent a hand for each player card player1_hand[5], player2_hand[5], player3_hand[5], player4_hand[5]; //Now the part ye' been askin' aboot //Somewhere along the line you can do something like this: if (is_one_pair(player1_hand)) { //code to handle hand containing 1 pair } else if(is_two_pair(player1_hand)) { //code to handle hand containing 2 pair } else if(is_three_of_kind(player1_hand)) { //code to handle hand containing 3 of a kind } else if(is_straight(player1_hand)) { //code to handle hand containing a straight } else if(is_flush(player1_hand)) { //code to handle hand containing a flush } else if(is_full_house(player1_hand)) { //code to handle hand containg a full house } else if(is_four_of_kind(player1_hand)) { //code to handle hand containing 4 of a kind } else if(is_straight_flush(player1_hand)) { //code to handle a straight flush } else high_card(player1_hand)); { //get the high card of the hand }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.