ComeçarComece de graça

Function to simulate one round with betting

Now let us write a function that simulates one round under the von Neumann model, with betting incorporated.

Player B will observe their value, and decide whether to bet $1 or not. If the decision to bet is made, then the two players compare values and the higher value wins. Note that if Player B bets and wins, the result is positive 1; if they bet and lose, the result is negative 1. If Player B decides not to bet, then no money is won or lost by either player.

Here, we will assume that Player B has a fixed strategy: if their value is above a certain cutoff, then they will bet. This cutoff, bet_cutoff, will be the argument to the function.

Este exercício faz parte do curso

Probability Puzzles in R

Ver curso

Instruções do exercício

  • Determine whether Player B will decide to bet.
  • If they do bet, return the result of the bet using the ifelse function.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

one_round <- function(bet_cutoff){
  a <- runif(n = 1)
  b <- runif(n = 1)
  # Fill in betting condition
  if(___){
    # Return result of bet
    return(___)
  } else {
    return(0)
  }  
}
Editar e executar o código