Exercise: MiniWarGame. In this exercise, we will implement a mini version of the card game War....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Exercise: MiniWarGame. In this exercise, we will implement a mini version of the card game "War". There are 2 players, each having a deck with 6 "cards": There are two cards with value 1, two cards with value 2, and two cards with value 3. In every round each player pulls the top card from the deck - the player that has the highest number, will take both cards and add them at the rear of his deck (his original card first, then the opponent's card). If both players pull the same number - we flip a coin and the winner will take both cards. The game ends when one of the players has won all cards and the other player has an empty deck. We initialize the game by (randomly) setting a deck for each player. Then, as long as no deck is empty, we play the rounds. At the end we announce the winner. At the beginning of each round, print out the decks. If a coin was flipped, print out the player that won that round. At the end, print the decks and announce the winner. Alice starts with deck: 3 2 3 1 2 1 bob starts with deck: 3 1 3 2 2 1 Round: 1 ********** Alice: 3 2 3 1 21 bob: 3 1 3 2 2 1 flipped coin! bob won Round: 2 ****: ***** Alice: 2 3 1 2 1 bob: 1 3 2 2 1 3 3 Round: 3 ***** **** Alice: 3 1 2 1 2 1 bob: 3 2 2 1 3 3 flipped coin! bob won Round: 4 ********** Alice: 1 2 1 2 1 bob: 2 2 1 3 3 3 3 Round: 5 ********** Alice: 2 1 2 1 bob: 2 1 3 3 3 3 2 1 flipped coin! Alice won Round: 6 ********** Alice: 1 2 1 2 2 bob: 1 3 3 3 3 2 1 flipped coin! Alice won Round: 7 ********** Alice: 2 1 2 2 11 bob: 3 3 3 3 2 1 Round: 8 ********** Alice: 1 2 2 11 bob: 3 3 3 2 1 3 2 Round: 9 ********** Alice: 2 2 1 1 bob: 3 3 2 1 3 2 3 1 Round: 10 ********** Alice: 2 1 1 bob: 3 2 1 3 2 3 1 32 Round: 11 ****: *** Alice: 1 1 bob: 2 1 3 2 3 1 3 232 Round: 12 ********** Alice: 1 bob: 1 3 2 3 1 3 2 3 2 2 1 flipped coin! bob won bob won! Exercise: MiniWarGame. In this exercise, we will implement a mini version of the card game "War". There are 2 players, each having a deck with 6 "cards": There are two cards with value 1, two cards with value 2, and two cards with value 3. In every round each player pulls the top card from the deck - the player that has the highest number, will take both cards and add them at the rear of his deck (his original card first, then the opponent's card). If both players pull the same number - we flip a coin and the winner will take both cards. The game ends when one of the players has won all cards and the other player has an empty deck. We initialize the game by (randomly) setting a deck for each player. Then, as long as no deck is empty, we play the rounds. At the end we announce the winner. At the beginning of each round, print out the decks. If a coin was flipped, print out the player that won that round. At the end, print the decks and announce the winner. Alice starts with deck: 3 2 3 1 2 1 bob starts with deck: 3 1 3 2 2 1 Round: 1 ********** Alice: 3 2 3 1 21 bob: 3 1 3 2 2 1 flipped coin! bob won Round: 2 ****: ***** Alice: 2 3 1 2 1 bob: 1 3 2 2 1 3 3 Round: 3 ***** **** Alice: 3 1 2 1 2 1 bob: 3 2 2 1 3 3 flipped coin! bob won Round: 4 ********** Alice: 1 2 1 2 1 bob: 2 2 1 3 3 3 3 Round: 5 ********** Alice: 2 1 2 1 bob: 2 1 3 3 3 3 2 1 flipped coin! Alice won Round: 6 ********** Alice: 1 2 1 2 2 bob: 1 3 3 3 3 2 1 flipped coin! Alice won Round: 7 ********** Alice: 2 1 2 2 11 bob: 3 3 3 3 2 1 Round: 8 ********** Alice: 1 2 2 11 bob: 3 3 3 2 1 3 2 Round: 9 ********** Alice: 2 2 1 1 bob: 3 3 2 1 3 2 3 1 Round: 10 ********** Alice: 2 1 1 bob: 3 2 1 3 2 3 1 32 Round: 11 ****: *** Alice: 1 1 bob: 2 1 3 2 3 1 3 232 Round: 12 ********** Alice: 1 bob: 1 3 2 3 1 3 2 3 2 2 1 flipped coin! bob won bob won!
Expert Answer:
Answer rating: 100% (QA)
import random class MiniWarGame def initself selfplayer1deck 1 1 2 2 3 3 ... View the full answer
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
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...
-
Not all countries have a dominant legal tradition. Some countries because of their historical circumstances, have both a Roman law root and an English common law root. In this lecture, we'll talk...
-
Python Question needed solving is at bottom #Function implementing the Extended Euclidean Algorithm import mathdef egcd(a,b): # b must not be zero otherwise the concept of gcd will fail #base case if...
-
A 0.042-kg pet lab mouse sits on a 0.35-kg air-track cart, as shown in FIGURE 9-27. The cart is at rest, as is a second cart with a mass of 0.25 kg. The lab mouse now jumps to the second cart. After...
-
In Exercises determine whether the statement is true or false. If it is false, explain why or give an example that shows it is false. The differential equation y' = xy - 2y + x - 2 can be written in...
-
Consider the net cash flows and salvage values shown below. Assume the alternatives can be indefinitely renewed with the same cash flows and salvage values. Using a MARR of 8%, specify the planning...
-
David James is a cost accountant and business analyst for Doorknob Design Company (DDC), which manufactures expensive brass doorknobs. DDC uses two direct cost categories: direct materials and direct...
-
Airport Passenger Processing: As an IT Manager you were tasked to improve the performance of the local Airport Passenger Processing system . This is to make the Airport more efficient and more...
-
The financial statements of Tarbet Township contain the following data regarding financial position: Governmental fund balances $ 5,000,000 Capital assets used in governmental activities $2,375,000...
-
ABC, Inc. needs some new equipment. The equipment would cost $200,000 if purchased and would be depreciated straight-line over 4 years. No salvage is expected. Alternatively, the company can lease...
-
The company that I have chosen for this week is Starbucks: Locate the financial statements for Starbucks that provides segmented financial information. Provide an overview of what is revealed about...
-
In August 2005, Paula Preparer was retained as accountant and tax return preparer for a new corporate client. In reviewing the prior returns of the client, Paula noticed that substantial deductions...
-
Compute capital gain in hands of Mrs. Parminder for the A.Y. 2021-22. Mrs. Parminder has jewellery, being gifted on 1/04/2005 by her brother Jitendar. Jitendar acquired such asset for Rs 60,000 as on...
-
The radius r of a circle is increasing at a rate of 6 centimeters per minute. Find the rate of change of the area when r = 30 centimeters. cm/min
-
4: Each question contains statements followed by two conclusions, A and B. Mark option 1, if only conclusion A follows. Mark option 2, if only conclusion B follows. Mark option 3, if both conclusions...
-
After reaping a massive reward from a high-risk investment, Jamila now seeks a safer investment with stable and promising returns. She now has two options: Stock investment: Due to the success of...
-
Record the following selected transactions for March in a two-column journal, identifying each entry by letter: (a) Received $10,000 from Shirley Knowles, owner. (b) Purchased equipment for $35,000,...
-
I express my undying love for my wife through weekly purchases of roses that cost $5 each. A. Suppose you have known me for a long time and you have seen my economic circumstances change with time....
-
Expanding Health Insurance Coverage: Some countries are struggling with the problem of expanding the fraction of the population that has good health insurance. A: Continue with the set-up first...
-
Acquisitions of Up-Start Firms by Incumbents: Large software companies often produce a variety of different software, and sometimes a small up-start develops a competing product. The large firm then...
-
Discuss the main differences between the traditional and the modern finance paradigm in understanding the behavior of individual investors.
-
Discuss the disposition effect and the proposed explanations for this effect.
-
Define and describe the process of worrying within the finance domain.
Study smarter with the SolutionInn App