Write a program that deals a five-card poker hand. The write functions to accomp
ID: 3626751 • Letter: W
Question
Write a program that deals a five-card poker hand. The write functions to accomplish each of the following:Determine whether the hand contains a pair.
Determine whether the hand contains two pairs.
Determine whether the hand contains three of a kind (e.g., three jacks).
Determine whether the hand contains four of a kind (e.g., four aces).
Determine whether the hand contains a flush (i.e., all five cards of the same suit).
Determine whether the hand contains a straight (i.e., five cards of consecutive face values).
The code must be in C#
This is what I have so far:
using System;
using System.Windows.Forms;
namespace DeckOfCards
{
public partial class DeckOfCardsForm : Form
{
private Card[] deck = new Card[ 52 ]; // deck of 52 cards
private int currentCard; // count which card was just dealt
// default constructor
public DeckOfCardsForm()
{
// Required for Windows Form Designer support
InitializeComponent();
} // end constructor
// handles form at load time
private void DeckForm_Load( object sender, EventArgs e )
{
string[] faces = { "Ace", "Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen",
"King" };
string[] suits = { "Hearts", "Diamonds", "Clubs", "Spades" };
currentCard = -1; // no cards have been dealt
// initialize deck
for ( int i = 0; i < deck.Length; i++ )
deck[ i ] = new Card( faces[ i % 13 ], suits[ i / 13 ] );
} // end method DeckForm_Load
// handles dealButton Click
private void dealButton_Click( object sender, EventArgs e )
{
Card dealt = DealCard();
// if dealt card is null, then no cards left
// player must shuffle cards
if ( dealt != null )
{
displayLabel.Text = dealt.ToString();
statusLabel.Text = "Card #: " + currentCard;
} // end if
else
{
displayLabel.Text = "NO MORE CARDS TO DEAL";
statusLabel.Text = "Shuffle cards to continue";
} // end else
} // end method dealButton_Click
// shuffle cards
private void Shuffle()
{
Random randomNumber = new Random();
Card temporaryValue;
currentCard = -1;
// swap each card with randomly selected card (0-51)
for ( int i = 0; i < deck.Length; i++ )
{
int j = randomNumber.Next( 52 );
// swap cards
temporaryValue = deck[ i ];
deck[ i ] = deck[ j ];
deck[ j ] = temporaryValue;
} // end for
dealButton.Enabled = true; // shuffled deck can now deal cards
} // end method Shuffle
// deal a card if the deck is not empty
private Card DealCard()
{
// if there is a card to deal then deal it
// otherwise signal that cards need to be shuffled by
// disabling dealButton and returning null
if ( currentCard + 1 < deck.Length )
{
currentCard++; // increment count
return deck[ currentCard ]; // return new card
} // end if
else
{
dealButton.Enabled = false; // empty deck cannot deal cards
return null; // do not return a card
} // end else
} // end method DealCard
// handles shuffleButton Click
private void shuffleButton_Click( object sender, EventArgs e )
{
displayLabel.Text = "SHUFFLING...";
Shuffle();
displayLabel.Text = "DECK IS SHUFFLED";
} // end method shuffleButton_Click
} // end class DeckForm
}
What I am unsure about is how to determine a pair, two of a kind, three of a kind, and four of a kind.
Thanks.
Explanation / Answer
2 3 #include 4 #include 5 #include 6 7 /* function prototypes */ 8 void shuffle( int deck[][ 13 ] ); 9 void deal(int deck[][ 13 ], int hand[][ 2 ], char *suit[], char *face[] ); 10 void pair( int hand[][ 2 ], char *suit[], char *face[] ); 11 void threeOfKind( int hand[][ 2 ], char *suit[], char *face[] ); 12 void fourOfKind( int hand[][ 2 ], char *suit[], char *face[] ); 13 void straightHand( int hand[][ 2 ], char *suit[], char *face[] ); 14 void flushHand( int hand[][ 2 ], char *suit[], char *face[] ); 15 16 int main() 17 { 18 char *suit[ 4 ] = { "Hearts", "Diamonds", "Clubs", "Spades" }; 19 char *face[ 13 ] = { "Ace", "Deuce", "Three", "Four", "Five", 20 "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" }; 21 int deck[ 4 ][ 13 ]; /* represents deck of cards */ 22 int hand[ 5 ][ 2 ]; /* represents hand */ 23 int row, column; /* loop counters */ 24 25 /* loop through rows of deck */Exercises 7 26 for ( row = 0; rowRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.