Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[20 points] Problem 4 In this problem you will write some code to simulate the game of Miniopoly (a very rough approximation of Monopoly). The

[20 points] Problem 4

In this problem you will write some code to simulate the game of Miniopoly (a very rough approximation of Monopoly). The game consists of a round board with 40 cells numbered from 00 to 3939, where cell 00 and would-be 4040 are coincident and called GO. A player starts at GO with $200 in their pocket. On each turn the player rolls a pair of dice and move the number of cells equal to the sum of two dices. Landing on different cells have different results:

  • Cells 28131725, and 33 causes you two draw a card. The cards may tell you to collect $50 or $100, or pay the bank $50 or $75. There is always an equal probability associated with drawing each of these possible cards.

  • Cell 1, 7, and 10 does not trigger any actions.

  • Cell 20 is Lottery. If a player lands on cell 20, then they are awarded a Lottery bonus of $500, this should be the input variable to your miniopoly_turn function called bonus.

  • Cell 30 is Go To Jail. If a player lands on cell 30, they would be locked up in jail.

  • If a player starts a turn in Jail, they roll a pair of dice:

    • If the player rolls doubles (i.e. the dice have equal values), then the player moves from Cell 10 a number of Cells equal to the sum of the dice.

    • If the player rolls anything other than doubles, then she pays the bank $25 and remains in Jail.

  • If a player passes or lands on GO, they collect $200.

  • If a player lands on other cells not mentioned above, they pay the bank an amount equal to the cell number (e.g. if they land on cell 19, they pay the bank $19).

If at any point the player has $0 or less they go bankrupt and the game ends.

See here for an example of the Miniopoly board layout.

Part A: Complete the function miniopoly_turn below. The function should simulate one turn of Miniopoly. It should take as arguments the player's current location on the board as well as the player's current cash reserves and the amount of the Lottery (Cell 20) bonus, and return the player's new location and cash reserves after the turn has completed. Note that if a player goes bankrupt during the game you should return their cash as 0 instead of a negative value.

In [ ]:

def miniopoly_turn(state, cash, bonus=500):
 # roll two dice
 a = np.random.randint(1, 7)
 b = np.random.randint(1, 7)
 
 # Your code here.
 
 
 return state, cash

In [ ]:

 

Part B: Use your function from Part A to stimulate at least 5000 games of Miniopoly that consists 20 turns and 40 turns, respectively. Make a density histogram of the player's cash amount at the end of the game under the both the 20-turn and 40-turn scenarios. Plot both histograms on the same set of axes, the histogram box faces should be slightly transparent and of different colors, so as to be able to tell the 2 game-length scenarios apart. For both histograms, use bins of width $250, starting at 0 on the left and extending as far to the right as needed. As always, be sure to label your axes and include an informative legend.

In [ ]:

# Your code here.

Part C: Use your code from Part A and Part B to estimate the probability that a player goes bankrupt in the 60 turns. Simulate at least 10,000 games.

In [ ]:

# Your code here.

Part D: Use your code from Part A and Part B to estimate the probability that a player goes bankrupt in a 60 turn game given that they have been to Jail at least twice and never won a Lottery. Is a player more or less likely to go bankrupt if they've been to jail twice and never won a Lottery? Simulate at least 10,000 games.

NOTE: If a player is already in jail and failed to roll a double, she will remain in Jail, which would increase the number of time she has been to jail by one.

In [ ]:

# Your code here.

image text in transcribed

[20 pointsProblem 4 In this problem you will write some code to simulate the game of Miniopoly (a very rough approximation of Monopoly). The game consists of a round board with 40 cells numbered from 0 to 39, where cell 0 and would-be 40 are coincident and called GO. A player starts at GO with $200 in their pocket. On each turn the player rolls a pair of dice and move the number of cells equal to the sum of two dices. Landing on different cells have different results: Cells 2, 8, 13, 17, 25, and 33 causes you two draw a card. The cards may tell you to collect $50 or $100, or pay the bank $50 or $75. There is always an equal probability associated with drawing each of these possible cards. Cell 1, 7, and 10 does not trigger any actions. . Cell 20 is Lottery. If a player lands on cell 20, then they are awarded a Lottery bonus of $500, this should be the input variable to your miniopoly_turn function called bonus. Cell 30 is Go To Jail. If a player lands on cell 30, they would be locked up in jail. If a player starts a turn in Jail, they roll a pair of dice: If the player rolls doubles i.e. the dice have equal values), then the player moves from Cell 10 a number of Cells equal to the sum of the dice. . If the player rolls anything other than doubles, then she pays the bank $25 and remains in Jail. If a player passes or lands on GO, they collect $200. . If a player lands on other cells not mentioned above, they pay the bank an amount equal to the cell number (e.g. if they land on cell 19, they pay the bank $19). If at any point the player has $0 or less they go bankrupt and the game ends. See here for an example of the Miniopoly board layout. Part A Complete the function miniopoly_turn below. The function should simulate one turn of Miniopoly. It should take as arguments the player's current location on the board as well as the player's current cash reserves and the amount of the Lottery (Cell 20) bonus, and return the player's new location and cash reserves after the turn has completed. Note that if a player goes bankrupt during the game you should return their cash as O instead of a negative value. def miniopoly_turn(state, cash, bonus=500): #roll two dice a = np.random. randint(1,7) b = np.random.randint(1,7) # Your code here. return state, cash Part B: Use your function from Part A to stimulate at least 5000 games of Miniopoly that consists 20 turns and 40 turns, respectively. Make a density histogram of the player's cash amount at the end of the game under the both the 20-turn and 40-turn scenarios. Plot both histograms on the same set of axes, the histogram box faces should be slightly transparent and of different colors, so as to be able to tell the 2 game-length scenarios apart. For both histograms, use bins of width $250, starting at 0 on the left and extending as far to the right as needed. As always, be sure to label your axes and include an informative legend. # Your code here. Part C: Use your code from Part A and Part B to estimate the probability that a player goes bankrupt in the 60 turns. Simulate at least 10,000 games. # Your code here. Part D: Use your code from Part A and Part B to estimate the probability that a player goes bankrupt in a 60 turn game given that they have been to Jail at least twice and never won a Lottery. Is a player more or less likely to go bankrupt if they've been to jail twice and never won a Lottery? Simulate at least 10,000 games. NOTE: If a player is already in jail and failed to roll a double, she will remain in Jail, which would increase the number of time she has been to jail by one. # Your code here. [20 pointsProblem 4 In this problem you will write some code to simulate the game of Miniopoly (a very rough approximation of Monopoly). The game consists of a round board with 40 cells numbered from 0 to 39, where cell 0 and would-be 40 are coincident and called GO. A player starts at GO with $200 in their pocket. On each turn the player rolls a pair of dice and move the number of cells equal to the sum of two dices. Landing on different cells have different results: Cells 2, 8, 13, 17, 25, and 33 causes you two draw a card. The cards may tell you to collect $50 or $100, or pay the bank $50 or $75. There is always an equal probability associated with drawing each of these possible cards. Cell 1, 7, and 10 does not trigger any actions. . Cell 20 is Lottery. If a player lands on cell 20, then they are awarded a Lottery bonus of $500, this should be the input variable to your miniopoly_turn function called bonus. Cell 30 is Go To Jail. If a player lands on cell 30, they would be locked up in jail. If a player starts a turn in Jail, they roll a pair of dice: If the player rolls doubles i.e. the dice have equal values), then the player moves from Cell 10 a number of Cells equal to the sum of the dice. . If the player rolls anything other than doubles, then she pays the bank $25 and remains in Jail. If a player passes or lands on GO, they collect $200. . If a player lands on other cells not mentioned above, they pay the bank an amount equal to the cell number (e.g. if they land on cell 19, they pay the bank $19). If at any point the player has $0 or less they go bankrupt and the game ends. See here for an example of the Miniopoly board layout. Part A Complete the function miniopoly_turn below. The function should simulate one turn of Miniopoly. It should take as arguments the player's current location on the board as well as the player's current cash reserves and the amount of the Lottery (Cell 20) bonus, and return the player's new location and cash reserves after the turn has completed. Note that if a player goes bankrupt during the game you should return their cash as O instead of a negative value. def miniopoly_turn(state, cash, bonus=500): #roll two dice a = np.random. randint(1,7) b = np.random.randint(1,7) # Your code here. return state, cash Part B: Use your function from Part A to stimulate at least 5000 games of Miniopoly that consists 20 turns and 40 turns, respectively. Make a density histogram of the player's cash amount at the end of the game under the both the 20-turn and 40-turn scenarios. Plot both histograms on the same set of axes, the histogram box faces should be slightly transparent and of different colors, so as to be able to tell the 2 game-length scenarios apart. For both histograms, use bins of width $250, starting at 0 on the left and extending as far to the right as needed. As always, be sure to label your axes and include an informative legend. # Your code here. Part C: Use your code from Part A and Part B to estimate the probability that a player goes bankrupt in the 60 turns. Simulate at least 10,000 games. # Your code here. Part D: Use your code from Part A and Part B to estimate the probability that a player goes bankrupt in a 60 turn game given that they have been to Jail at least twice and never won a Lottery. Is a player more or less likely to go bankrupt if they've been to jail twice and never won a Lottery? Simulate at least 10,000 games. NOTE: If a player is already in jail and failed to roll a double, she will remain in Jail, which would increase the number of time she has been to jail by one. # Your code here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions