play_game: Play Game Function

Description Usage Arguments Details Value Examples

View source: R/montyhall.R

Description

The play_game() function combines all the steps described above into a single function to play one round of the game.

Usage

1

Arguments

To

start play_game() the variable new.game is created using the function create_game(). The next variable created is first.pick. first.pick uses the function select_door() and simulates the initial door choice of the player. After the initial choice is made, the variable opened.door is introduced using the function open_goat_door(). The variables new.game and first.pick are passed through the function open_goat_door() to ensure that the door opened by this function is not equal to the door chosen by the contestant and not equal to a car door. The next variables in this function are final.pick.stay and final.pick.switch. These variables represent the player's choice of staying with their initial choice first.pick or switching to the third door. In final.pick.stay the player chooses not to switch and in final.pick.stay, the player chooses to switch. This decision is then passed through the next variable strategy. The next variable is outcome. The play_game() function compares outcomes using both strategies, "stay" and "switch". This allows the function to decide which strategy is more effective at winning. The variable game.results is the final variable determined by the play_game() function.

Details

This function allows the user to simulate game play through the use of a single function as described in the parameters below. Each simulation is the equivalent of one round of the game.

Value

The variable game.results is a data frame returned by the function play_game(). The results are a single character vector that indicate "WIN" or "LOSE".

Examples

1

RTrehern-ASU/montyhall documentation built on Sept. 22, 2020, 12:42 a.m.