Idiot’s Delight is a fairly simple game of solitaire, yet it is difficult to win. The goal is to draw all of the cards from the deck, and end up with no cards left in your hand. You will run through the deck of cards one time. Start by dealing 4 cards to your hand. You will always look at the last 4 cards in your hand. If the ranks of the “outer” pair (1st and 4th) are the same, discard all four cards. Otherwise, if the suits of the “inner” pair (2nd and 3rd) are the same, discard those 2 cards only. If you have less than 4 cards, draw enough to have 4 cards in your hand. If the deck is empty, the game is over. Your score will be the number of cards that remain in your hand. Like in golf, the lower the score the better. Create a new Python module in a file named “idiots_delight.py”. Add a function called deal_hand that creates a standard deck of cards, deals out a single hand of 4 cards and returns both the hand and the deck. Remember that for the last assignment, you created several functions to emulate cards. To help with testing, don’t shuffle the deck at this time. Deal out 4 cards. Add a function called discard that declares parameters for a hand and the number of cards to discard. If the number is not either 4 or 2, or there are less than 4 cards in the hand, simply return the hand. If the number is 4, discard the last 4 cards from the hand, otherwise if the number is 2, discard the 2 inner cards (the 2 before the last card). Return the hand.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. Idiot’s Delight is a fairly simple game of solitaire, yet it is difficult to win. The goal is to draw all of the cards from the deck, and end up with no cards left in your hand. You will run through the deck of cards one time. Start by dealing 4 cards to your hand. You will always look at the last 4 cards in your hand. If the ranks of the “outer” pair (1st and 4th) are the same, discard all four cards. Otherwise, if the suits of the “inner” pair (2nd and 3rd) are the same, discard those 2 cards only. If you have less than 4 cards, draw enough to have 4 cards in your hand. If the deck is empty, the game is over. Your score will be the number of cards that remain in your hand. Like in golf, the lower the score the better.
  2. Create a new Python module in a file named “idiots_delight.py”. Add a function called deal_hand that creates a standard deck of cards, deals out a single hand of 4 cards and returns both the hand and the deck. Remember that for the last assignment, you created several functions to emulate cards. To help with testing, don’t shuffle the deck at this time. Deal out 4 cards.
  3. Add a function called discard that declares parameters for a hand and the number of cards to discard. If the number is not either 4 or 2, or there are less than 4 cards in the hand, simply return the hand. If the number is 4, discard the last 4 cards from the hand, otherwise if the number is 2, discard the 2 inner cards (the 2 before the last card). Return the hand.
  4. We’ll build up the function in this module that plays the main game. Add a function called play_round that declares parameters for a deck and a hand of cards (lists of card tuples). Start by ensuring that you have enough cards to play a round with. If you have less than 4 cards, draw from the deck until you have a hand of 4 cards. Print out the hand. At the end of the function, if there are still cards in the deck, draw one more card and print the hand. Return the deck and the hand. Hint: testing at this point should avoid either of the discard scenarios described in step 1 to ensure adding code for those scenarios later doesn’t impact your testing.
  5. The next step in the play_round function is immediately after ensuring that you have at least 4 cards. Loop until you have less than 4 cards, or you did not discard. Check if the 1st and 4th of the last four cards are the same rank. If they are, remove all 4 of those cards from the hand by calling your discard function.
  6. The next step in the play_round function is only done when the previous check of the 1st and 4th of the last 4 cards are not the same rank. In this case, check if the 2nd and 3rd cards of the last four are the same suit. If they are, remove only the 2nd and 3rd cards from the hand.
  7. Add a main function to your “idiots_delight.py” module. You need to deal a hand, and call play_round module until there are no cards left in the deck. When the game has ended, print a message telling them the game has ended as well as how many cards are left in their hand. If there are 0 cards left, also let them know that they are a winner, otherwise, give them encouragement to try again. Manually run the game twice. You should get the same score both times since we didn’t shuffle the deck. See the example snippets from two games below:
Expert Solution
steps

Step by step

Solved in 6 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education