Question: Provide Miranda code to implement the following simple game, which shuffles a collection of an arbitrary number of playing cards. Do not write a complex

Provide Miranda code to implement the following simple game, which shuffles a collection of an arbitrary number of playing cards. Do not write a complex user interface. A shuffle function should take as arguments a number, a list of elements and a function that can be applied to two cards to determine if they are equal. Each element in the list represents a playing card, where each playing card has a suit(Spades,Hearts,Diamonds and Clubs) and a number(there are thirteen possible numbers, with the top four in increasing order being Jack,Queen,King and Ace). The Miranda code should produce as its output a shuffled version of the input list (the second argument). The function should shuffle the list of cards as many times as is indicated by the first argument. The action of shuffling should cut the deck in half and then interleave the cards, with the previous top card now being the second card in the pack. For example, if a list of four items A, B, C and D is shuffled once the result should be C, A, D, B. If that result is shuffled again the result should be D, C, B, A. If the list contains an odd number of cards, you should detect this case and provide an appropriate solution. You should explain your solution what it does and why. Your function should detect the following two errors and provide appropriate error handling: (i) where there are more than 52 elements in the input list, and (ii) where there is any duplicated card in the input list. Next provide Miranda code to deal four hands of five cards from a shuffled pack of 52 cards, then to determine whether there is a winning hand and if so which hand would win according to the following rules: The best hand is a straight flush where all five cards are in the same suit, and where the five values make a sequence with no gaps. If two or more players have a straight flush, the one that wins is the one with the highest top-ranked card (an Ace is the highest ranked card). If two or more players have identically high straight flushes, the hands are ranked by suit in descending order: Spades, Hearts, Diamonds, Clubs. Second-best is four of a kind: four of the same-valued cards (one from each suit). If two or more players have four of a kind the winner is the one with the highest value. Third-best is a full house that contains three cards of one value and two cards (a pair) of another value (e.g.3 Kings and 2 Jacks). Hands are ranked first by the value of the triplet, and then by the value of the pair. Fourth-best is a flush that contains five cards all of the same suit. Hands are ranked firstly by the value of the highest card, then of the second card, and so on.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!