ambo strategy function to return a random play, and tests for when one of the length of plays is less than 3 and  otherwise. I have tried running it many times on a single scenario to estimate the probability for each return but the results are somehow confusing.  Question: Write a series for the roshambo function below to test that it works as expected. (this could be testthat::expect_equal or testthat::expect_true or testthat::expect_error tests). Thank you. roshambo <- function(plays){     # return random play

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter11: Nonlinear Programming
Section11.10: Quadratic Programming
Problem 1P
icon
Related questions
Question

So I have the following roshambo strategy function to return a random play, and tests for when one of the length of plays is less than 3 and  otherwise. I have tried running it many times on a single scenario to estimate the probability for each return but the results are somehow confusing. 

Question: Write a series for the roshambo function below to test that it works as expected. (this could be testthat::expect_equal or testthat::expect_true or testthat::expect_error tests). Thank you.

roshambo <- function(plays){
    # return random play
    if (length(plays) < 3){
        return(sample(c("R", "P", "S"), 1))
    } 
    
    # else find most common
    most_common <- names(which.max(table(plays)))
    if (most_common == "S"){
        return("R")
    } else if (most_common == "R"){
        return("P")
    } else {
        return("S")
    }
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole