Question

This has to be done in Haskell only. Write a program that: Given 2 poker hands...

This has to be done in Haskell only.

Write a program that:

Given 2 poker hands (5 cards) in list of tuples form (ex. hand1 = [(1,0),(2,0),(3,0),(4,0),(5,0)]). Each tuple represents a card where first number of a tuple is its value (1=Ace, 2=2,...,10=10, 11=Jack, 12=Queen, 13=King) and second number its suit (0=Clubs, 1=Diamonds, 2=Hearts, 3=Spades) so (1,0) will be Ace of Clubs, or (5,2) will be 5 of Hearts, etc.

Rule website: https://www.fgbradleys.com/et_poker.asp

These hands are generated by an end user. Write a program that will analyze each hand according to the rules from the
website above (regular poker rules) and decide a winner (output a winning hand).

There will be no ties. If both hands have the same type, we will implement tie breaking
based on the ranks of the cards. For example, if both hands are a flush, then the hand with
the card of highest rank is declared the winner. If both hands have a pair, then the hand
whose pair is higher wins. For example, a pair of Kings beats a pair of Sevens. If both hands
have the same pair, i.e. each hand has a pair of threes, then the hand with the next highest
card wins. If both hands have the same pair, and the same high card, we check the 2nd
highest card. And so on, and so forth.

If, after comparing hands and ranks, it turns out that the hands are identical, we move on to
tie-breaking by suit. If both hands have a pair of threes, and all other cards are of the same
rank, then the hand with the three of spades will win. Keep in mind that tie breaking based
on suit only comes into effect when tie breaking based on rank is impossible. Suits are
ranked from lowest to highest in the following order: Clubs < Diamonds < Hearts < Spades.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 ort hand by suit: smallest suit card first .... (Finding a flush is eaiser that way) --------------------------------------------- */ public static void sortBySuit( Card[] h ) { int i, j, min_j;  /* --------------------------------------------------- The selection sort algorithm --------------------------------------------------- */ for ( i = 0 ; i < h.length ; i ++ ) { /* --------------------------------------------------- Find array element with min. value among h[i], h[i+1], ..., h[n-1] --------------------------------------------------- */ min_j = i; // Assume elem i (h[i]) is the minimum for ( j = i+1 ; j < h.length ; j++ ) { if ( h[j].suit() < h[min_j].suit() ) { min_j = j; // We found a smaller suit value, update min_j } }  /* --------------------------------------------------- Swap a[i] and a[min_j] --------------------------------------------------- */ Card help = h[i]; h[i] = h[min_j]; h[min_j] = help; } }
Add a comment
Know the answer?
Add Answer to:
This has to be done in Haskell only. Write a program that: Given 2 poker hands...
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
  • This activity needs to be completed in the Python language. This program will simulate part of...

    This activity needs to be completed in the Python language. This program will simulate part of the game of Poker. This is a common gambling game comparing five-card hands against each other with the value of a hand related to its probability of occurring. This program will simply be evaluating and comparing hands, and will not worry about the details of dealing and betting. Here follow the interesting combinations of cards, organized from most common to least common: Pair --...

  • discrete structure Recall that a standard deck of 52 cards has 4 suits (hearts, diamonds, spades, and clubs), each of w...

    discrete structure Recall that a standard deck of 52 cards has 4 suits (hearts, diamonds, spades, and clubs), each of which has 13 ranks: 2-10, Jack, Queen, King, and Ace (in order from lowest to highest). Order of cards in a hand does not matter (a) (10 points) A full house is 3 cards of one rank and 2 of another rank. How many full houses are there in a 5-card hand if either the pair or the 3 of...

  • 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...

  • 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...

  • 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...

  • Python Programming: An individual playing card is represented as a string of two characters: • the...

    Python Programming: 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 as letter T to make all card ranks to be single letters) • the second character is from "cdhs" and represents the suit (clubs, diamonds, hearts and spades respectively). For example, "Jd" would be the jack of diamonds, and "4s" would be...

  • Write in Java! Do NOT write two different programs for Deck and Card, it should be...

    Write in Java! Do NOT write two different programs for Deck and Card, it should be only one program not 2 separate ones!!!!!! !!!!!!!!!!!!!!!Use at least one array defined in your code and two array lists defined by the operation of your code!!!!!!!!!!!!!!!!!!!!! The array should be 52 elements and contain a representation of a standard deck of cards, in new deck order. (This is the order of a deck of cards new from the box.) The 2 Array lists...

  • Example set of 52 poker playing cards Suit Ace 2 10 Jack Queen King 3- What...

    Example set of 52 poker playing cards Suit Ace 2 10 Jack Queen King 3- What is the sample space for a regular 52 card-deck? Spades Hearts 4-Determine the sample space Diamonds for choosing one of the four possible aces from a standard deck of cards. clubs

  • May i please get help with this? Thank you for your time. [Poker] Poker is a...

    May i please get help with this? Thank you for your time. [Poker] Poker is a card played with a standard 52 card playing deck (https://en.wikipedia.org/wiki/Standard_52-card_deck). There are many variants of poker. However, for this problem we will not concern ourselves with any specific version, but rather the types of poker hands possible. Assume five cards out of the standard 52 card deck are dealt to a player. The order that the player receives the cards does not matter. One...

  • 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...

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