Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in R! Create a function play_solo() that will simulate a game of chutes and ladders for one player. The function will accept the following arguments:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

in R!

Create a function play_solo() that will simulate a game of chutes and ladders for one player. The function will accept the following arguments: board to represent the board the same argument used in show_board) verbose with default value FALSE to represent whether the function should display every move to the screen The function will output the following values in a list: turns: how many turns it took to complete a game chute_tally: a vector of length j with the count of how many times each chute was used. j is the number of chutes that exist in the board. If a chute is never used in the game, the tally for that chute is 0. ladder_tally: a vector of length k with the count of how many times each ladder was used. k is the number of ladders that exist in the board. move_log: a vector containing a record or log of all the spaces a player landed on. The spinner has values 1 through 6 and each number shows up with equal probability. You can use the following function to simulate a spin. spin set.seed (10) > play_solo(board, TRUE) Turn 1 Start at o Spinner: 3 Turn ends at: 3 Turn 2 Start at 3 Spinner: 1 Landed on: 4 Ladder! Turn ends at: 14 Turn 3 Start at 14 Spinner: 2 Landed on: 16 Chute! Turn ends at: 6 Turn 4 Start at 6 Spinner: 4 Turn ends at: 10 Turn 5 Start at 10 Spinner: 6 Landed on: 16 Chute! Turn ends at: 6 Turn 6 Start at 6 Spinner: 3 Landed on: 9 Ladder! Turn ends at: 31 Turn 7 Start at 31 Spinner: 2 Turn ends at : 33 Turn 8 Start at 33 Start at 33 Spinner: 2 Turn ends at: 35 Turn 9 Start at 35 Spinner: 2 Turn ends at: 37 Turn 10 Start at 37 Spinner: 5 Turn ends at: 42 Turn 11 Start at 42 Spinner: 6 Turn ends at: 48 Turn 12 Start at 48 Spinner: 6 Turn ends at: 54 Turn 13 Start at 54 Spinner: 3 Turn ends at: 57 Turn 14 Start at 57 Spinner: 6 Turn ends at: 63 Turn 15 Start at 63 Spinner: 2 Turn 16 Start at 65 Spinner: 5 Turn ends at: 70 Turn 17 Start at 70 Spinner: 5 Turn ends at: 75 Turn 18 Start at 75 Spinner: 5 Landed on: 80 Ladder! Turn ends at: 100 $turns [1] 18 $chute_tally [1] 2000OOOOOO $ladder_tally [1] 0 1 1 0 0 0 0 0 1 $move_log [1] 3 14 6 10 6 31 33 35 37 42 48 54 57 63 65 70 75 100 Verbose output: The start of each turn begins with Turn x It announces where the player is located at the start of the turn: Start at x It announces what the player spun: Spinner: x - If the player lands on a special space, it says Landed on: x Verbose output: The start of each turn begins with Turn x It announces where the player is located at the start of the turn: Start at x It announces what the player spun: Spinner: x - If the player lands on a special space, it says Landed on: x - It will announce Chute! or Ladder! depending on what type of special space it is. It announces where the player ends the turn: Turn ends at: x When verbose = FALSE, it will only return the contents of the list: > set.seed (10) > play_solo(board, FALSE) $turns [1] 18 $chute_tally [1] 2 OOOOOOOOO $ladder_tally [1] 0 1 1 0 0 0 0 0 1 $move_log [1] 3 14 6 10 6 31 33 35 37 42 48 54 57 63 65 70 75 100 To demonstrate that your play_solo() function works, produce the verbose output for a game with less than 30 turns. If your random number generator is the same as mine, I suggest set.seed (5) which had a total of 28 moves (for me). Create a function play_solo() that will simulate a game of chutes and ladders for one player. The function will accept the following arguments: board to represent the board the same argument used in show_board) verbose with default value FALSE to represent whether the function should display every move to the screen The function will output the following values in a list: turns: how many turns it took to complete a game chute_tally: a vector of length j with the count of how many times each chute was used. j is the number of chutes that exist in the board. If a chute is never used in the game, the tally for that chute is 0. ladder_tally: a vector of length k with the count of how many times each ladder was used. k is the number of ladders that exist in the board. move_log: a vector containing a record or log of all the spaces a player landed on. The spinner has values 1 through 6 and each number shows up with equal probability. You can use the following function to simulate a spin. spin set.seed (10) > play_solo(board, TRUE) Turn 1 Start at o Spinner: 3 Turn ends at: 3 Turn 2 Start at 3 Spinner: 1 Landed on: 4 Ladder! Turn ends at: 14 Turn 3 Start at 14 Spinner: 2 Landed on: 16 Chute! Turn ends at: 6 Turn 4 Start at 6 Spinner: 4 Turn ends at: 10 Turn 5 Start at 10 Spinner: 6 Landed on: 16 Chute! Turn ends at: 6 Turn 6 Start at 6 Spinner: 3 Landed on: 9 Ladder! Turn ends at: 31 Turn 7 Start at 31 Spinner: 2 Turn ends at : 33 Turn 8 Start at 33 Start at 33 Spinner: 2 Turn ends at: 35 Turn 9 Start at 35 Spinner: 2 Turn ends at: 37 Turn 10 Start at 37 Spinner: 5 Turn ends at: 42 Turn 11 Start at 42 Spinner: 6 Turn ends at: 48 Turn 12 Start at 48 Spinner: 6 Turn ends at: 54 Turn 13 Start at 54 Spinner: 3 Turn ends at: 57 Turn 14 Start at 57 Spinner: 6 Turn ends at: 63 Turn 15 Start at 63 Spinner: 2 Turn 16 Start at 65 Spinner: 5 Turn ends at: 70 Turn 17 Start at 70 Spinner: 5 Turn ends at: 75 Turn 18 Start at 75 Spinner: 5 Landed on: 80 Ladder! Turn ends at: 100 $turns [1] 18 $chute_tally [1] 2000OOOOOO $ladder_tally [1] 0 1 1 0 0 0 0 0 1 $move_log [1] 3 14 6 10 6 31 33 35 37 42 48 54 57 63 65 70 75 100 Verbose output: The start of each turn begins with Turn x It announces where the player is located at the start of the turn: Start at x It announces what the player spun: Spinner: x - If the player lands on a special space, it says Landed on: x Verbose output: The start of each turn begins with Turn x It announces where the player is located at the start of the turn: Start at x It announces what the player spun: Spinner: x - If the player lands on a special space, it says Landed on: x - It will announce Chute! or Ladder! depending on what type of special space it is. It announces where the player ends the turn: Turn ends at: x When verbose = FALSE, it will only return the contents of the list: > set.seed (10) > play_solo(board, FALSE) $turns [1] 18 $chute_tally [1] 2 OOOOOOOOO $ladder_tally [1] 0 1 1 0 0 0 0 0 1 $move_log [1] 3 14 6 10 6 31 33 35 37 42 48 54 57 63 65 70 75 100 To demonstrate that your play_solo() function works, produce the verbose output for a game with less than 30 turns. If your random number generator is the same as mine, I suggest set.seed (5) which had a total of 28 moves (for me)

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

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago

Question

3. Did you seek anyones advice?

Answered: 1 week ago

Question

7. What traps should she avoid?

Answered: 1 week ago

Question

5. What decision-making model would you advocate to this person?

Answered: 1 week ago