How many times the player landed on each positions - create


This is a partial monopoly simulation only tracks how many times the player landed on each positions.

I want you to create a simulation of the classic board game, Monopoly.

You will not be simulating the entire game. You will be simulating only the movement of pieces, and will keep track of which squares the pieces land on.

If you have never played Monopoly before, I recommend watching a few videos on the topic.

https://www.youtube.com/watch?v=4Hfe97Q5kul

(https://www.youtube.com/watch?v=4Hfe97Q5kul)

Rules for movement

The Monopoly Board is effectively a circle with 40 spaces on which a player can land. Players move from space to space around the board in a circle (square).

The number of spaces a player moves is determined by the roll of 2 dice. Most often, the player will roll the dice, land on a space, and end his turn there.

There are, however, several exceptions which provide the primary source of variation in space landing:

One space sends players directly to jail. This space never counts as having been "landed upon." As soon as the player lands here, he is immediately sent to jail, and the jail space gets counted as landed upon. This is the only space on the game board that moves a player's piece.

If a player rolls doubles (two of the same number), the player moves his piece, and then gets to roll the dice again for another move. However, if a player rolls doubles three times in a row, he is sent directly to jail. (The third space that the player would have 'landed on' does not count, but the jail space gets counted as landed on.)

Card Decks
A player can land on a "Chance" or "Community Chest" space. When a player lands on these spaces, he draws a card from the respective deck and follows its instructions. The instructions will sometimes give money to or take money from the player with no change in the player's position on the board. Other times, the card will instruct the player to move to another space on the board. The list of cards that can be drawn from each deck is provided below.
There are nine cards in the Chance deck that move the player's token. There are two cards in the Community Chest deck that move the player's token. All other cards do not move the player's token.
A card may say 'move to the nearest railroad' or 'move to the nearest utility' or even 'go to property xxx'. In these cases, the player always moves forward. So if a player is on 'Oriental Avenue,' the nearest railroad is `Pennsylvania Railroad' and NOT 'Reading Railroad.'


The Chance and Community Chest spaces always get counted as "landed on" even if the card drawn moves the player to another space or sends him to jail. In those cases, a tally is counted for the Chance/Community Chest space, the token is moved, and then a tally is counted for the space where the player ends his turn.
Jail
Jail is the most complicated aspect of this simulation.
If a player lands on space 11 (Jail), he is not in Jail. He is 'just visiting.' His play continues on as normal.
A player can be placed in jail in several ways: he can roll doubles three times in a row. He can land on the "go to jail space." He can draw a card that sends hims to jail.
When in jail, the player has the option to pay a fee to 'get out,' or he can choose not to pay the fee. If he pays the fee, he is out of jail, and his play continues normally as before.
If he chooses not to pay the fee, he rolls the dice. If he rolls doubles on the dice, he gets out of jail and move the number of spaces the dice show. However, despite rolling doubles, he does not roll again. He takes his move out of jail and his turn ends. If he does not roll doubles, he stays in jail.
A player cannot stay in jail for more than three turns. On his third turn in jail, he rolls the dice and moves the number of spaces the dice show no matter what. If they are doubles, he moves those spaces for free. If he does not roll doubles, he moves those spaces, but must also pay a fee.


Your Simulation
Your task is to run 2,000 simulations of a game for one player that rolls the dice 100 times. This is a total of 4 hundred thousand dice rolls - 2000 games x 100 rolls x 2 dice.
Your task is to keep track of where the player lands. Advance the tokens around the board according to the rules. Keep in mind the special situations involving the cards, jail, and rolling doubles.
For your convenience, I have created the necessary data frames for the game board, and the two decks of cards.

2016f7/29 Homework
gameboard <- data.frame(space = 1:40, title = c("Go" , "Mediterranean Avenue" , "Community Ches t" , "Baltic Avenue" , "Income Tax" , "Reading Railroad" , "Oriental Avenue" , "Chance" , "Vermo nt Avenue" , "Connecticut Avenue" , "Jail" , "St. Charles Place" , "Electric Company" , "States Avenue" , "Virginia Avenue" , "Pennsylvania Railroad" , "St. James Place" , "Community Chest" , "Tennessee Avenue" , "New York Avenue" , "Free Parking" , "Kentucky Avenue" , "Chance" , "India na Avenue" , "Illinois Avenue" , "B & 0 Railroad" , "Atlantic Avenue" , "Ventnor Avenue" , "Wate r Works" , "Marvin Gardens" , "Go to jail" , "Pacific Avenue" , "North Carolina Avenue" , "Commu nity Chest" , "Pennsylvania Avenue" , "Short Line Railroad" , "Chance" , "Park Place" , "Luxury Tax" , "Boardwalk"))
chancedeck <- data.frame(index = 1:15, card = c("Advance to Go" , "Advance to Illinois Ave." , "Advance to St. Charles Place" , "Advance token to nearest Utility" , "Advance token to the near est Railroad" , "Take a ride on the Reading Railroad" , "Take a walk on the Boardwalk" , "Go to
Jail" , "Go Back 3 Spaces" , "Bank pays you dividend of $50" , "Get out of Jail Free" , "Make g eneral repairs on all your property" , "Pay poor tax of $15" , "You have been elected Chairman o f the Board" , "Your building loan matures"))
communitydeck <- data.frame(index = 1:16, card = c("Advance to Go" , "Go to Jail" , "Bank error in your favor ??? Collect $200" , "Doctor's fees Pay $50" , "From sale of stock you get $45" , "Get Out of Jail Free" , "Grand Opera Night Opening" , "Xmas Fund matures" , "Income tax refund" , "Life insurance matures ??? Collect $100" , "Pay hospital fees of $100" , "Pay school tax of $150" , "Receive for services $25" , "You are assessed for street repairs" , "You have won seco nd prize in a beauty contest" , "You inherit $100"))
You can 'hard code' the functions that handle the decks. In other words, you can write something along the lines of
## for chance deck
if(carddrawn == 1)
code changes player position to space 1 # advance to go
if(carddrawn == 2)
code changes player position to space 25 # advance to Illinois avenue
# etc.
• • •
To get you started, here is a simple function to roll two dice.
## for your convenience. feeL free to modify if you wish. dice <- function(){
faces <- sample(1:6, 2, replace=TRUE)
if(faces[1] == faces[2]) doubles = TRUE
else doubles = FALSE
movement = sum(faces)
return(list(faces=faces, doubles=doubles, movement=movement))

Your final output should be a list of the spaces on the board and how many times the space was landed upon. Arrange the table in descending order of frequency of landing.

You do not have to simulate or track money at all in this simulation.
2016f7/29 Homework

Tips

At first blush, the task may seem overwhelming.

Break the task into smaller manageable parts.

Start with a simulation that moves pieces around the board and keeps track of where they land. Then add complexity one part at a time.

Add something so landing on "Go to jail" sends the player to jail.

Add functions for the Chance and Community Chest decks. Keep in mind that some cards have no effect on player movement, while other cards do.

Add something to allow players to move again after doubles.

Finally implement the Jail. You'll need to keep track of whether the player is actually in jail or not, how many turns the player has been in jail, and the rules for getting out.

Because of the random nature of sampling, I do not expect everyone's results to match perfectly, but some overall trends should appear.

If you are unable to implement all parts of the solution, that is also okay. I cannot give you full credit, but please indicate what you were able to implement and what you were not able to implement. You will be graded on what you were able to complete.

It may or may not be to your advantage to create a reference class for the player, keeping track of the player's position, whether he's in jail, what turn it is in jail, and anything else.

If the player rolls the dice, then he moves to the chance position. He gets a chance card to move again. We should both count the chance position and the second position.

Request for Solution File

Ask an Expert for Answer!!
Dissertation: How many times the player landed on each positions - create
Reference No:- TGS01534434

Expected delivery within 24 Hours