create a ridiculous game based (in level of ridiculousness) on the original series Star Trek game...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
create a ridiculous game based (in level of ridiculousness) on the original series Star Trek game "Fizzbin," invented by Captain Kirk to confuse his gangster-imitating captors on Sigma lotia II. The program will randomly generate two hands of two or three "cards, depending on whether it's day or night. (We will randomly generate a zero or one, with zero meaning it's day and one meaning it's night.) If either hand has two cards with the same value, that player has a "shronk" and they automatically lose. To simplify the idea of a "card," a card will be a number from 1 to 13. So, for example, we might generate these two hands: Player 1's hand: 12 Player 2's hand: 4 4 In this example, it is "night" (because player 2 has three cards). Player 2 has a "shronk," so they have lost. The program will display the cards as above and print the following messages after displaying the hands (these are the messages for the hands above-the messages will be appropriate to whether each player has lost or not): 7 1 Player I has not lost. Player 2 has lost. Think about how you would solve this problem before reading through the step-by-step instructions and hints below, and solve as much as you can on your own. You have learned everything you need to know to solve this problem in lessons 1-3. 1. CREATE A TEMPLATE FOR PYTHON PROGRAMS. In this step, you are going to create a template that you can use for Python programs. This will be useful for all of the programs you will write. You will start from the template in other labs, for programming assignments, and for practice problems. A template is very useful because, if it is well written, it will give you a well-structured starting point with reminders about what to add and where. A template allows you to focus on your program's unique functionality. Create a template by opening IDLE and choosing File -> New File. Create a docstring at the top of the new window with a place for the program description, with your name, and with a place for the date. (Remember that a doestring is a comment that begins with three quotes.) Under the docstring, add a comment for import statements. (Remember a comment begins with a pound sign/ hash tag--#.) Import statements will go below the comment. If you are writing a turtle program, you will import the turtle under this comment. (We are not writing a turtle program here.) If you are writing a program that uses the math or random libraries, you will import them under this comment, etc. Next, add comments to the program for your variable annotations, for any input you might be obtaining, for processing, and for output. In all, there will be a docstring and five comments in your template. If you want to, you can add import statements to your template under your import comment, but remember to remove them if you write a program that doesn't require those libraries to be imported. Save your template as template.py. 2. IMPORT THE RANDOM LIBRARY AND RANDOMLY GENERATE TWO HANDS Save your template.py programas labl.py, or fuzzbun.py, or some other name that will make sense to you. Every time you work from your template, remember to save it with a different name so your template remains the same. You might want to remove your name from the docstring at the top of the program so that your lab will be anonymous. (You don't have to - you can leave your name if you want to.) The fuzzbun game requires that we generate two "hands" of cards. Remember that a "card" is going to be a random number between 1 and 13, and a "hand" will be two cards if it's day, and three cards for the second player if it's night. We'll add the day/night part of this program later, so for now, we're going to generate two hands of two cards each. That means we're going to generate four random numbers total, and store them in four variables so we can check for a shronk and print them out. Begin by importing the random library under your imports comment. Now annotate your four variables under your variable annotation comment. What would be good names for these variables? Two of the cards will belong to player 1, and two will belong to player 2 (or you might call them dealer and player, or hand 1 and hand 2), so names like playerl_cardl, dealer_cardl, player2_cardl, hand2_cardl, etc., would be good choices. (Pick one way to refer to the two players and be consistent.) The data type for these variables will be int, as we're randomly generating integers between 1 and 13 for each card. Annotate four variables for the cards under your variable annotation comment. You should now generate random numbers between 1 and 13 and assign them to each of your card variables. Here is an example of what that code might look like for one card (your code might be different, depending on your variable names): handl_cardl= random.randint (1, 13) Write a comment above your code, relating the code to the problem. For example, you might write a comment such as, "Randomly generate two hands of two cards each." After you've randomly generated all four cards, write one or more print statements to print them out so you can test that this part of the program is working. Write a comment above your print statements. For example, your output might look like this: Player 1's hand: 3 13 Player 2 's hand: 2 13 Note that we will solve this problem one piece at a time, make sure that piece is working, and move on. That way if there's an error, it will relate to any new code we've added, as we've already tested the older code. 3. DETERMINE IF THERE'S A LOSER If either hand contains two of the same card, the player has a "shronk" and has lost. It is possible that both players might lose. If neither player has a shronk, then both players have not lost. We will need to write some logic to determine if either of the players has lost. Let's store that information in two variables - one if the first player (or hand, or dealer) has a shronk, and a second if the second player (or hand, or player) has a shronk. Annotate two variables of type bool. You might call them playerl_shronk, player2_shronk, for example. Use whatever words you are using in your game to refer to the two players (player, hand, or dealer/player). These variables will be True if the respective player has a shronk (has lost), and False otherwise. How do we know if a player has a shronk? A player has a shronk if they have two of the same card in their hand. This is quite easy to check if there are only two cards - check if the player's two cards are the same. If they are, set that player's shronk variable to True. If they are not, set that player's shronk variable to False. There are several different ways to write this code. Here are a few: You can initialize the Boolean shronk variables to False, and set them to True if the card values are the same. You can not initialize the Boolean shronk variables, and use an if/else statement to set them to True if the card values are the same, and False otherwise. You can use an assignment statement to assign the result of the comparison directly to the Boolean shronk variable. Write a comment over the code in which you determine if each player has a shronk. Remember that one player can have a shronk, two players can have a shronk, or zero players can have a shronk. What one player has in their hand has nothing to do with the other player. Pick the correct logic for this situation. Print out whether the player has won or lost after you have set the shronk variable, after your code that displays the cards. For example, here is some code that prints whether player 1 has lost: if handl_shronk: print ("Player 1 has lost.") else: print ("Player 1 has not lost.") Here is an example of what the program might look running. There are two executions here: RESTART: D: lesson3_lab_sample_solution.py Player 1's hand: 4 Player 2's hand:: 12 12 Player 1 has not lost. Player 2 has lost. >>> RESTART: D:/ lesson3_1ab_sample_solution.py Player 1's hand:: 10 2 Player 2's hand: 2 3 Player 1 has not lost. Player 2 has not lost.. 4. ADD DAY AND NIGHT In the game of fuzzbun, if it's night, player 2 (hand 2/player/whatever you called the variable) gets a third card. We will randomly generate a 1 or 0 to determine the time of day. A 0 means it's day and a 1 means it's night. To enhance the program with day and night, you will need to do the following: Annotate a bool variable to store whether it's day or night. Randomly generate a number between 0 and 1 and set the bool variable according to that value. You might need to annotate an int variable to store the random number. If it's night, generate one more card for the second player. Annotate that card variable and generate a value for it only if it's night. Print the card only if it's night. . Change your code to determine if the second player has lost if it's night. It will be more complicated now, because you must compare card1 to card 2, card1 to card3, and card2 to card 3. Here is an example of the enhanced game executing three times: RESTART: D: /lesson3_lab_sample_solution.py Player 1's hand: 8 8 Player 2 's hand: 12 11 11 Player 1 has lost. Player 2 has lost. >>> RESTART: D: lesson3_lab_sample_solution.py Player 1's hand: 2 Player 2 's hand: 5 11 Player 1 has not lost. Player 2 has not lost. >>> 3 RESTART: D: lesson3_lab_sample_solution.py Player 1's hand: 8 12 Player 2's hand: 13 6 Player 1 has not lost. Player 2 has not lost. 5. TESTING Test your program thoroughly! Because you are using random number generation, you will want to insert code for testing that hard-codes values for the four cards and for day and night. You should test the following cases: 1. Day and neither player has a shronk 2. Day and player1 has a shronk 3. Day and player 2 has a shronk 4. Day and both player1 and player2 have a shronk 5. Night and neither player has a shronk 6. Night and player 1 has a shronk 7. Night and player 1 does not have a shronk, player 2 has a shronk with the first and second cards 8. Night and player 1 does not have a shronk, player 2 has a shronk with the first and third cards 9. Night and player 1 does not have a shronk, player 2 has a shronk with the second and third cards 10. Night and player 1 has a shronk, player 2 has a shronk with the first and second cards 11. Night and player 1 has a shronk, player 2 has a shronk with the first and third cards 12. Night and player 1 has a shronk, player 2 has a shronk with the second and third cards Determine the appropriate output for each of those test cases and run your program by setting the variables accordingly. For example, for the final test case with player 2 having a shronk with the second and third cards and player 1 not having a shronk, we might set the variables as: handl_card1= 1 handl_card2 = 2 hand2 cardl= 3 hand2_card2 = 4 hand2 card3 - 4 is_night True And we would expect the following output: Player 1's hand: 1 2 Player 2's hand: 3 4 4 Player 1 has not lost. Player 2 has lost. Paste your program running at the bottom of the program file as a comment with each test case described, for example: ##Test case 9: Night and player 1 does not have a shronk, ##player 2 cards 2 and 3 #*Player 1's hand: # #1 2 ## Player 2's hand: ##3 4 4 ##Player 1 has not lost. # #Player 2 has lost. When you are done, comment out your testing code for your final test case, but leave it in the program so your reviewer can see if you completed the testing correctly and offer suggestions if not. In other words, comment out the final hard-coded values. The program you submit should randomly generate the cards. create a ridiculous game based (in level of ridiculousness) on the original series Star Trek game "Fizzbin," invented by Captain Kirk to confuse his gangster-imitating captors on Sigma lotia II. The program will randomly generate two hands of two or three "cards, depending on whether it's day or night. (We will randomly generate a zero or one, with zero meaning it's day and one meaning it's night.) If either hand has two cards with the same value, that player has a "shronk" and they automatically lose. To simplify the idea of a "card," a card will be a number from 1 to 13. So, for example, we might generate these two hands: Player 1's hand: 12 Player 2's hand: 4 4 In this example, it is "night" (because player 2 has three cards). Player 2 has a "shronk," so they have lost. The program will display the cards as above and print the following messages after displaying the hands (these are the messages for the hands above-the messages will be appropriate to whether each player has lost or not): 7 1 Player I has not lost. Player 2 has lost. Think about how you would solve this problem before reading through the step-by-step instructions and hints below, and solve as much as you can on your own. You have learned everything you need to know to solve this problem in lessons 1-3. 1. CREATE A TEMPLATE FOR PYTHON PROGRAMS. In this step, you are going to create a template that you can use for Python programs. This will be useful for all of the programs you will write. You will start from the template in other labs, for programming assignments, and for practice problems. A template is very useful because, if it is well written, it will give you a well-structured starting point with reminders about what to add and where. A template allows you to focus on your program's unique functionality. Create a template by opening IDLE and choosing File -> New File. Create a docstring at the top of the new window with a place for the program description, with your name, and with a place for the date. (Remember that a doestring is a comment that begins with three quotes.) Under the docstring, add a comment for import statements. (Remember a comment begins with a pound sign/ hash tag--#.) Import statements will go below the comment. If you are writing a turtle program, you will import the turtle under this comment. (We are not writing a turtle program here.) If you are writing a program that uses the math or random libraries, you will import them under this comment, etc. Next, add comments to the program for your variable annotations, for any input you might be obtaining, for processing, and for output. In all, there will be a docstring and five comments in your template. If you want to, you can add import statements to your template under your import comment, but remember to remove them if you write a program that doesn't require those libraries to be imported. Save your template as template.py. 2. IMPORT THE RANDOM LIBRARY AND RANDOMLY GENERATE TWO HANDS Save your template.py programas labl.py, or fuzzbun.py, or some other name that will make sense to you. Every time you work from your template, remember to save it with a different name so your template remains the same. You might want to remove your name from the docstring at the top of the program so that your lab will be anonymous. (You don't have to - you can leave your name if you want to.) The fuzzbun game requires that we generate two "hands" of cards. Remember that a "card" is going to be a random number between 1 and 13, and a "hand" will be two cards if it's day, and three cards for the second player if it's night. We'll add the day/night part of this program later, so for now, we're going to generate two hands of two cards each. That means we're going to generate four random numbers total, and store them in four variables so we can check for a shronk and print them out. Begin by importing the random library under your imports comment. Now annotate your four variables under your variable annotation comment. What would be good names for these variables? Two of the cards will belong to player 1, and two will belong to player 2 (or you might call them dealer and player, or hand 1 and hand 2), so names like playerl_cardl, dealer_cardl, player2_cardl, hand2_cardl, etc., would be good choices. (Pick one way to refer to the two players and be consistent.) The data type for these variables will be int, as we're randomly generating integers between 1 and 13 for each card. Annotate four variables for the cards under your variable annotation comment. You should now generate random numbers between 1 and 13 and assign them to each of your card variables. Here is an example of what that code might look like for one card (your code might be different, depending on your variable names): handl_cardl= random.randint (1, 13) Write a comment above your code, relating the code to the problem. For example, you might write a comment such as, "Randomly generate two hands of two cards each." After you've randomly generated all four cards, write one or more print statements to print them out so you can test that this part of the program is working. Write a comment above your print statements. For example, your output might look like this: Player 1's hand: 3 13 Player 2 's hand: 2 13 Note that we will solve this problem one piece at a time, make sure that piece is working, and move on. That way if there's an error, it will relate to any new code we've added, as we've already tested the older code. 3. DETERMINE IF THERE'S A LOSER If either hand contains two of the same card, the player has a "shronk" and has lost. It is possible that both players might lose. If neither player has a shronk, then both players have not lost. We will need to write some logic to determine if either of the players has lost. Let's store that information in two variables - one if the first player (or hand, or dealer) has a shronk, and a second if the second player (or hand, or player) has a shronk. Annotate two variables of type bool. You might call them playerl_shronk, player2_shronk, for example. Use whatever words you are using in your game to refer to the two players (player, hand, or dealer/player). These variables will be True if the respective player has a shronk (has lost), and False otherwise. How do we know if a player has a shronk? A player has a shronk if they have two of the same card in their hand. This is quite easy to check if there are only two cards - check if the player's two cards are the same. If they are, set that player's shronk variable to True. If they are not, set that player's shronk variable to False. There are several different ways to write this code. Here are a few: You can initialize the Boolean shronk variables to False, and set them to True if the card values are the same. You can not initialize the Boolean shronk variables, and use an if/else statement to set them to True if the card values are the same, and False otherwise. You can use an assignment statement to assign the result of the comparison directly to the Boolean shronk variable. Write a comment over the code in which you determine if each player has a shronk. Remember that one player can have a shronk, two players can have a shronk, or zero players can have a shronk. What one player has in their hand has nothing to do with the other player. Pick the correct logic for this situation. Print out whether the player has won or lost after you have set the shronk variable, after your code that displays the cards. For example, here is some code that prints whether player 1 has lost: if handl_shronk: print ("Player 1 has lost.") else: print ("Player 1 has not lost.") Here is an example of what the program might look running. There are two executions here: RESTART: D: lesson3_lab_sample_solution.py Player 1's hand: 4 Player 2's hand:: 12 12 Player 1 has not lost. Player 2 has lost. >>> RESTART: D:/ lesson3_1ab_sample_solution.py Player 1's hand:: 10 2 Player 2's hand: 2 3 Player 1 has not lost. Player 2 has not lost.. 4. ADD DAY AND NIGHT In the game of fuzzbun, if it's night, player 2 (hand 2/player/whatever you called the variable) gets a third card. We will randomly generate a 1 or 0 to determine the time of day. A 0 means it's day and a 1 means it's night. To enhance the program with day and night, you will need to do the following: Annotate a bool variable to store whether it's day or night. Randomly generate a number between 0 and 1 and set the bool variable according to that value. You might need to annotate an int variable to store the random number. If it's night, generate one more card for the second player. Annotate that card variable and generate a value for it only if it's night. Print the card only if it's night. . Change your code to determine if the second player has lost if it's night. It will be more complicated now, because you must compare card1 to card 2, card1 to card3, and card2 to card 3. Here is an example of the enhanced game executing three times: RESTART: D: /lesson3_lab_sample_solution.py Player 1's hand: 8 8 Player 2 's hand: 12 11 11 Player 1 has lost. Player 2 has lost. >>> RESTART: D: lesson3_lab_sample_solution.py Player 1's hand: 2 Player 2 's hand: 5 11 Player 1 has not lost. Player 2 has not lost. >>> 3 RESTART: D: lesson3_lab_sample_solution.py Player 1's hand: 8 12 Player 2's hand: 13 6 Player 1 has not lost. Player 2 has not lost. 5. TESTING Test your program thoroughly! Because you are using random number generation, you will want to insert code for testing that hard-codes values for the four cards and for day and night. You should test the following cases: 1. Day and neither player has a shronk 2. Day and player1 has a shronk 3. Day and player 2 has a shronk 4. Day and both player1 and player2 have a shronk 5. Night and neither player has a shronk 6. Night and player 1 has a shronk 7. Night and player 1 does not have a shronk, player 2 has a shronk with the first and second cards 8. Night and player 1 does not have a shronk, player 2 has a shronk with the first and third cards 9. Night and player 1 does not have a shronk, player 2 has a shronk with the second and third cards 10. Night and player 1 has a shronk, player 2 has a shronk with the first and second cards 11. Night and player 1 has a shronk, player 2 has a shronk with the first and third cards 12. Night and player 1 has a shronk, player 2 has a shronk with the second and third cards Determine the appropriate output for each of those test cases and run your program by setting the variables accordingly. For example, for the final test case with player 2 having a shronk with the second and third cards and player 1 not having a shronk, we might set the variables as: handl_card1= 1 handl_card2 = 2 hand2 cardl= 3 hand2_card2 = 4 hand2 card3 - 4 is_night True And we would expect the following output: Player 1's hand: 1 2 Player 2's hand: 3 4 4 Player 1 has not lost. Player 2 has lost. Paste your program running at the bottom of the program file as a comment with each test case described, for example: ##Test case 9: Night and player 1 does not have a shronk, ##player 2 cards 2 and 3 #*Player 1's hand: # #1 2 ## Player 2's hand: ##3 4 4 ##Player 1 has not lost. # #Player 2 has lost. When you are done, comment out your testing code for your final test case, but leave it in the program so your reviewer can see if you completed the testing correctly and offer suggestions if not. In other words, comment out the final hard-coded values. The program you submit should randomly generate the cards.
Expert Answer:
Related Book For
Discovering Advanced Algebra An Investigative Approach
ISBN: 978-1559539845
1st edition
Authors: Jerald Murdock, Ellen Kamischke, Eric Kamischke
Posted Date:
Students also viewed these programming questions
-
Based on your understanding, provide an overview of career adaptability highlighting the four domains (career concern, career control, career confidence and career curiosity). In your answer,...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
1.Discuss 5 (five) direct benefits and 5 (five) indirect benefits that GovTech would have if the Enterprise Architecture is successfully implemented in GoxTech (500 words) 2.Discuss 5 (five) key...
-
Explain the economic basis for the U shape of the long-run average total cost curve.
-
Calculate the potential due to a thin circular ring of radius a and mass M for points lying in the plane of the ring and exterior to it. The result can be expressed as an elliptic integral. Assume...
-
What role does systems thinking play in fostering a holistic approach to organizational design and management? explain
-
Using the gasoline mileage data in Table B. 3 find the eigenvectors associated with the smallest eigenvalues of \(\mathbf{X}^{\prime} \mathbf{X}\). Interpret the elements of these vectors. What can...
-
For each pair of funds listed below, select the fund that would be less risky and briefly explain your answer. a. Growth versus growth-and-income b. Equity-income versus high-grade corporate bonds c....
-
What do you believe are the main differentiators between Core, Core Plus, Value Add and Opportunistic apartment communities? Do you believe it is better to lease student housing by the unit or by...
-
Consider the following January transactions: 1. On January 1, 20X1, three persons, James, Bosh, and Wade, formed JBW Corporation. JBW is a wholesale distributor of electronic equipment. The company...
-
Businesses use budgets to plan for the future. Thats what you will be doing for this assignment. Rather than budgeting for your current financial situation, I want you to put together a budget for...
-
Under a contract with QT Corporation, Gold Medical ships an assortment of medical supplies. When QT opens the crates, it discovers that the supplies are the wrong assortment but agrees to accept them...
-
Siva contracts to sell to the Marcos University Bookstore 10,000 black USB flash drives. Siva identifies the flash drives by boxing up the order, attaching labels with Marcoss address to the cartons,...
-
Paper City, a microbrewery, entered into a contract with La Resistance, a beer distribution company, under which La Resistance would purchase beer from Paper City and distribute it to retailers....
-
Under a destination contract, title passes at the time and place of shipment. (True/False)
-
In what situations can a buyer or lessee revoke their acceptance of goods?
-
There are two cubes. The first cube has a volume of 1,000 cubic units. The second cube is smaller than the first, with sides only half as long. What is the volume of the second cube?
-
Recall that Chapter 8 described the binary search algorithm for finding a particular entry in an ordered list. The idea behind binary search is to begin looking in the exact center of the list. If...
-
The most recent test scores in a chemistry class were {74, 71, 87, 89, 73, 82, 55, 78, 80, 83, 72} What was the average (mean) score?
-
A golden rectangle is a rectangle that can be divided into a square and another rectangle that is also a golden rectangle similar to the original. In the figure at right, ABCD is a golden rectangle...
-
Describe a data set that might produce each of these continuous distribution graphs. Indicate the range of values on the x-axis. a. b. c.
-
The following is the trial balance of Sangeeta Udhyog Ltd. as on 31st March 2006. Further information 1.The authorised share capital of the company consists of 4,00,000 equity shares of ` 10 each. 2....
-
The accountant of Pushpa Engineering Company Ltd. has prepared the following trial balance of the company as on 31st March, 2006. Further information 1. Authorised equity share capital of the company...
-
Following trial balance as at 31st March 2006 has been prepared from the account books of Mahesh Foods Ltd. Further information 1.The authorized capital of the company is 3 lac equity shares of ` 10...
Study smarter with the SolutionInn App