Question

I need to write a vb program for a poker game that uses a two-dimensional array......

I need to write a vb program for a poker game that uses a two-dimensional array... Here is the problem: A poker hand can be stored in a two-dimensional array. The statement Dim hand(3, 12) As Integer declares an array with 52 elements, where the first subscript ranges over the four suits and the second subscript ranges over the thirteen denominations. A poker hand is specified by placing 1%u2019s in the elements corresponding to the cards in the hand. Write a program that requests the five cards as input from the user, creates the related array, and passes the array to procedures to determine the type of the hand: flush (all cards have the same suit), straight (cards have consecutive denominations%u2014ace can come either before 2 or after King), straight flush, four-of-a-kind, full house (three cards of one denom- ination, two cards of another denomination), three-of-a-kind, two pairs, one pair, or none of the above.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

write a vb program for a poker game that uses a two-dimensional array... Here is the problem: A poker hand can be stored in a two-dimensional array. The statement Dim hand(3, 12) As Integer declares an array with 52 elements, where the first subscript ranges over the four suits and the second subscript ranges over the thirteen denominations. A poker hand is specified by placing 1%u2019s in the elements corresponding to the cards in the hand. Write a program that requests the five cards as input from the user, creates the related array, and passes the array to procedures to determine the type of the hand: flush (all cards have the same suit), straight (cards have consecutive denominations%u2014ace can come either before 2 or after King), straight flush, four-of-a-kind, full house (three cards of one denom- ination, two cards of another denomination), three-of-a-kind, two pairs, one pair, or none of the above.

vb program for a poker game

>
>Dim hand(1 To 4, 1 To 13) As Integer
>Dim suit As Integer
>Dim denom As Integer
>Dim suitTotal As Integer
>Dim denomTotal As Integer
>Dim cardFlag As Boolean
>Dim cardHand As String
>
>Private Sub cmdAnalysis_Click()
> picHand.Cls
> cardFlag = False
> Call changeData(hand())
> Call countData(hand(), suit, denom)
> Call findFlush(hand(), suit, denom, suitTotal, denomTotal, cardFlag,
>cardHand)
> Call findStraight(hand(), suit, denom, suitTotal, denomTotal, cardFlag,
>cardHand)
> Call findStraightFlush(hand(), suit, denom, suitTotal, denomTotal, cardFlag,
>cardHand)
> Call findFourOfAKind(hand(), suit, denom, suitTotal, denomTotal, cardFlag,
>cardHand)
> Call findThreeOfAKind(hand(), suit, denom, suitTotal, denomTotal, cardFlag,
>cardHand)
> Call findPairs(hand(), suit, denom, suitTotal, denomTotal, cardFlag,
>cardHand)
> Call findfullHouse(hand(), suit, denom, suitTotal, denomTotal, cardFlag,
>cardHand)
> Call showData(hand(), suit, denom, suitTotal, denomTotal, cardFlag,
cardHand)
>End Sub
>
>Private Sub changeData(hand() As Integer)
> ' Change strings (suit) and card denominations (denom) to 1s
> Dim i As Integer
> For i = 0 To 4
> suit = InStr(1, "CDHS", UCase(txtSuit(i).Text))
> Select Case UCase(txtDenom(i).Text)
> Case "A"
> denom = 1
> Case "J"
> denom = 11
> Case "Q"
> denom = 12
> Case "K"
> denom = 13
> Case Else
> denom = Val(txtDenom(i).Text)
> End Select
> If suit > 0 And denom > 0 Then
> hand(suit, denom) = 1
> End If
> Next i
>End Sub
>
>Private Sub countData(hand() As Integer, suit As Integer, denom As Integer)
> Dim i As Integer
> Dim j As Integer
> Dim m As Integer
> Dim n As Integer
> Dim suitCount As Integer
> Dim denomCount As Integer
> suitTotal = 0
> denomTotal = 0
>
> For i = 1 To 4 ' Count cards in suit
> suitCount = 0
> For j = 1 To 13
> suitCount = suitCount + hand(i, j)
> Next j
> If suitCount > suitTotal Then suitTotal = suitCount
> Next i
>
> For m = 1 To 13 ' Count card denominations
> denomCount = 0
> For n = 1 To 4
> denomCount = denomCount + hand(n, m)
> Next n
> If denomCount > denomTotal Then denomTotal = denomCount
> Next m
>
>End Sub
>
>Private Sub findFlush(hand() As Integer, suit As Integer, denom As Integer,
>suitTotal As Integer, denomTotal As Integer, cardFlag As Boolean, cardHand
>As String)
> If suitTotal = 5 Then
> cardFlag = True
> If cardFlag = True Then
> cardHand = "a flush."
> End If
> End If
>End Sub
>
>Private Sub findStraight(hand() As Integer, suit As Integer, denom As Integer,
>suitTotal As Integer, denomTotal As Integer, cardFlag As Boolean, cardHand
>As String)
> Dim i As Integer
> Dim j As Integer
> Dim countCards As Integer
> Dim foundIt As Boolean
> foundIt = False
> For i = 1 To 4
> countCards = 0
> For j = 1 To 13
> If hand(i, j) = 1 Then
> countCards = countCards + 1
> Else
> If countCards <> 5 Then
> countCards = 0
> End If
> End If
> If countCards = 5 Then
> foundIt = True
> End If
> Next j
> Next i
> If foundIt Then
> cardFlag = True
> If cardFlag = True Then
> cardHand = "a straight."
> End If
> End If
>End Sub
>
>Private Sub findStraightFlush(hand() As Integer, suit As Integer, denom
As
>Integer, suitTotal As Integer, denomTotal As Integer, cardFlag As Boolean,
>cardHand As String)
> Dim i As Integer
> Dim j As Integer
> Dim countCards As Integer
> Dim foundIt As Boolean
> foundIt = False
> For i = 1 To 4
> countCards = 0
> For j = 1 To 13
> If hand(i, j) = 1 Then
> countCards = countCards + 1
> Else
> If countCards <> 5 Then
> countCards = 0
> End If
> End If
> If countCards = 5 Then
> foundIt = True
> End If
> Next j
> Next i
> If foundIt Then
> cardFlag = True
> If cardFlag = True And suitTotal = 5 Then
> cardHand = "a straight flush!"
> End If
> End If
>End Sub
>
>Private Sub findFourOfAKind(hand() As Integer, suit As Integer, denom As
>Integer, suitTotal As Integer, denomTotal As Integer, cardFlag As Boolean,
>cardHand As String)
> If denomTotal = 4 Then
> cardFlag = True
> If cardFlag = True Then
> cardHand = "four of a kind!"
> End If
> End If
>End Sub
>
>Private Sub findThreeOfAKind(hand() As Integer, suit As Integer, denom As
>Integer, suitTotal As Integer, denomTotal As Integer, cardFlag As Boolean,
>cardHand As String)
> If denomTotal = 3 Then
> cardFlag = True
> If cardFlag = True Then
> cardHand = "three of a kind."
> End If
> End If
>End Sub
>
>Private Sub findPairs(hand() As Integer, suit As Integer, denom As Integer,
>suitTotal As Integer, denomTotal As Integer, cardFlag As Boolean, cardHand
>As String)
> If denomTotal = 2 Then
> cardFlag = True
> If cardFlag = True Then
> cardHand = "two of a kind."
> End If
> End If
>End Sub
>
>Private Sub findfullHouse(hand() As Integer, suit As Integer, denom As Integer,
>suitTotal As Integer, denomTotal As Integer, cardFlag As Boolean, cardHand
>As String)
> If denomTotal = 3 And denomTotal = 2 Then
> cardFlag = True
> If cardFlag = True Then
> cardHand = "full house!"
> End If
> End If
>End Sub
>
>Private Sub showData(hand() As Integer, suit As Integer, denom As Integer,
>suitTotal As Integer, denomTotal As Integer, cardFlag As Boolean, cardHand
>As String)
> If cardFlag = True Then
> picHand.Print "You have "; cardHand
> Else
> picHand.Print "Sorry, you have no hand."
> End If
>End Sub
>

Add a comment
Know the answer?
Add Answer to:
I need to write a vb program for a poker game that uses a two-dimensional array......
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help writing this program! Thanks in advance. Project4 Specifications: Determine Poker Hand A poker hand...

    Need help writing this program! Thanks in advance. Project4 Specifications: Determine Poker Hand A poker hand can be stored in a two-dimensional array. The statement: Dim aryintCards(4,14) as Integer (See AryCardExample.xlsx excel spreadsheet) declares an array which the first subscript 1-4 are the four suits and the second subscript ranges over the card denominations: 1-14: Ace, 2, ..., 10, Jack, Queen, King, Ace (repeated). First subscript of 0 is Total of each denomination. Second subscript of 0 is Total of...

  • 1. Find the probabilities of Poker hands not covered in class. Recall in a Poker game,...

    1. Find the probabilities of Poker hands not covered in class. Recall in a Poker game, 5 cards are drawn uniformly at random from a deck of 52 cards. Each deck has 13 denominations ({A, 2, 3, . . . , 10, J Q, K)) and 4 suits (4,◇,0,6 ). In what follows consecutive denominations are But (J,Q,K, A, 21 is not considered consecutive. Find the probabilities of a. Straight Flush (5 cards of consecutive denomination, all of the same...

  • A standard poker deck of 52 cards has four suits, (symbols C, H, S, and D) and thirteen ranks (sy...

    A standard poker deck of 52 cards has four suits, (symbols C, H, S, and D) and thirteen ranks (symbols A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, and K). Every card in the deck has both a value and a suit.1 A poker hand is any set of 5 cards from the standard poker deck. There are some special hands in poker, and these have ranks (i.e. some are better, some are worse). From best...

  • 18. This is an excellent exercise for practicing counting. Find the number of f hands, dealt...

    18. This is an excellent exercise for practicing counting. Find the number of f hands, dealt from a standard 52-card deck, that contain: (a) a royal flush (A-K-Q-J-10 all in one suit); (b) a straight flush (five cards of consecutive denominations all in one suit, but not royal flush); (c) four-of-a-kind (four cards of one denomination and one card of a different de nomination); (d) a full house (three cards of one denomination and t two of a different denomina...

  • Can someone please answer this by Friday? A poker deck consists of cards ranked 2; 3;...

    Can someone please answer this by Friday? A poker deck consists of cards ranked 2; 3; 4; 5; 6; 7; 8; 9; 10; J; Q;K;A (13 different ranks), each in four suits, for a total of 52 distinct cards. (a) What is the probability that a five-card poker hand drawn from a poker deck consists only of cards ranked 8; 9; 10; J; Q;K;A? (b) Find a probability of Three of a kind. This is, three cards of the same...

  • 1. In a standard five-card draw poker, each player receives 5 cards from a standard deck...

    1. In a standard five-card draw poker, each player receives 5 cards from a standard deck of 52 cards. Some possible hands in this game are su d in Table 1 below1 (a) Create a sample space to describe all possible hands Bill can play with Let E be the event that the hand contains at least two cards of the same rank and F be the event that the hand contains at least three cards of the same rank...

  • Write a Java program that deals a five-card poker hand and then determines which of the...

    Write a Java program that deals a five-card poker hand and then determines which of the following hands are contained in it: high card, pairs, two pair, three of a kind, flush. Test only for those hands. Use the numbers from 0 to 51 to represent the cards of the poker deck. 1. To deal the cards, your main method should call a secondary method that selects a random card. The secondary method should accept 5 integers that represent the...

  • Learning objectives 1. To implement decisions using if statements 2. To write statements using the boolean...

    Learning objectives 1. To implement decisions using if statements 2. To write statements using the boolean primitive data type. 3. To compare strings and/or characters. 4. To write loops using while or for. 5. To write functions Representing playing cards and hands of cards An individual playing card is represented as a string of two characters: • the first character is from "23456789TJQKA" and represents the rank, i.e., the number or value of the card. (Note that 10 is encoded...

  • 7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card...

    7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determinewhetherthehandcontainstwopairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determinewhetherthehandcontainsfourofakind(e.g.,fouraces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of...

  • With the code given write python code that prints the probablity of getting a straight in...

    With the code given write python code that prints the probablity of getting a straight in poker when you run 10**5 trails. HELPER CODE: # We will represent cards as a string, e.g., 'AC' will be Ace of Clubs # Denominations: 2, ..., 10, 'J' = Jack, 'Q' = Queen, 'K' = King, 'A' = Ace Denominations = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] # Suits 'S' = Spades, 'H' = Hearts, 'D' = Diamonds, 'C' = Clubs Suits = ['C', 'H', 'S', 'D'] #...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT