Get startedGet started for free

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.

This exercise is part of the course

Probability Puzzles in R

View Course

Exercise instructions

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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)
  }  
}
Edit and Run Code