Open malmufre opened 4 years ago
Hello,
I actually had a similar question. Should we simulate the 3 scenarios automatically in the game testing or should we like prompt the numbers from the user and then assign them to create_game() ?
For instance, I was thinking about something like this:
read_user <- function (){
num.goats <- readline (prompt = "Enter number of goats: ")
num.goats <- as.numeric (unlist (num.goats))
num.cars <- readline (prompt = "Enter number of cars: ")
num.cars <- as.numeric (unlist (num.cars))
game <- create_game (num.goats,num.cars)
return (game)
@malmufre That looks correct.
You are doing scenario analysis, so functions that allow you to examine difference scenarios are needed:
play_game( num.goats=8, num.cars=2)
play_game( num.goats=9, num.cars=1)
And then each scenario is evaluated through one simulation each:
results.df <- NULL # collector
for( i in 1:10000 ) # iterator
{
game.outcome <- play_game()
# binding step
play_game(num.goats=8, num.cars=2)
results.df <- rbind( results.df, game.outcome )
}
table( results.df )
If you think about it, the more doors you have the less impact that switching will have on the outcome.
So it should not be surprising the tables are looking more similar than the 3-door case. They should still be different, though.
@gzbib I think that's a cool idea and would definitely be one way to implement this type of game.
In this case results are presented in a knitted RMD document. You can't ask for user input inside of a knit.
You would also want to hard-code your scenarios, or even use a loop to explore ALL scenarios.
thank you Sir
@lecy Thank you !
I also would like to know if we are expected to include the codes for the 3 scenarios in part 2 which are:
1 car, 9 goats
2 cars, 8 goats
3 cars, 7 goats
So far I only have the code for the game with 3 cars and 7 goats. Would that be enough?
@malmufre Yes, you would need the three scenarios to compare them while answering the question.
@lecy Should we test the 3 scenarios as well?
Hi Prof. Lecy,
I want to ask you if I am running this correctly for the second part of lab 2. I have this code for the
play_game()
functionI tried to create the function for the 3 scenarios of the game with different arguments. Would this be okay?
As for the
for loop
what I did is this:And I repeated the same thing for the 2 other games. The codes are running just fine , however the tables I'm getting have similar values, so I just wanted to make sure if I am running this correctly.