DS4PS / cpp-527-fall-2020

http://ds4ps.org/cpp-527-fall-2020/
0 stars 1 forks source link

Lab2-Part 2 #9

Open malmufre opened 4 years ago

malmufre commented 4 years ago

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() function

play_game<-function ( num.goats=7, num.cars=3 )
{
  this.game <- create_game( num.goats, num.cars )
  my.initial.pick <- select_door( game=this.game )
  opened.door <- open_goat_door( this.game, my.initial.pick )

 my.final.pick.stay <- change_door( stay=T, game=this.game, 
                                   opened.door=opened.door, a.pick=my.initial.pick )

my.final.pick.switch <- change_door( stay=F, game=this.game,
                                     opened.door=opened.door, a.pick=my.initial.pick )

 outcome.stay <- determine_winner( final.pick=my.final.pick.stay, game=this.game )
outcome.switch <- determine_winner( final.pick=my.final.pick.switch, game=this.game )

  # game.results <- bundle the results
  # return( <<< game.results >>> )

  strategy <- c("stay","switch")
  outcome <- c(outcome.stay,outcome.switch)
  game.results <- data.frame( strategy, outcome,
                              stringsAsFactors=F )
  return( game.results )
}
play_game()
play_game( num.goats=8, num.cars=2) 
play_game( num.goats=9, num.cars=1) 

I 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:

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 ) 

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.

gzbib commented 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)
lecy commented 4 years ago

@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.

lecy commented 4 years ago

@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.

gzbib commented 4 years ago

thank you Sir

malmufre commented 4 years ago

@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:

So far I only have the code for the game with 3 cars and 7 goats. Would that be enough?

lecy commented 4 years ago

@malmufre Yes, you would need the three scenarios to compare them while answering the question.

malmufre commented 4 years ago

@lecy Should we test the 3 scenarios as well?