Skip to content

Instantly share code, notes, and snippets.

@corynissen
Created May 16, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corynissen/5526748a7f839a207335cc1db2dd8931 to your computer and use it in GitHub Desktop.
Save corynissen/5526748a7f839a207335cc1db2dd8931 to your computer and use it in GitHub Desktop.
trustgame2 <- function(investor_string,trustee_string){
#investor <- get(investor_string, envir = globalenv())
#trustee <- get(trustee_string, envir = globalenv())
investor <- investors[[investor_string]]
trustee <- trustees[[trustee_string]]
investordecision <- NULL
trusteedecision <- trustee[1]
investor[6] <- investor[6]+1
trustee[4] <- trustee[4]+1
if (investor[1]==0) investordecision <- investor[2]
if (investor[1]==1){
if (trustee[2]==1) investordecision <- investor[2]
if (trustee[2]==2) investordecision <- investor[3]
if (trustee[2]==3) investordecision <- investor[4]
if (trustee[2]==0) investordecision <- rbinom(1,1,0.5)
}
if (investordecision==1 && trustee[2]==1) trustee[2] <- 1
if (investordecision==1 && trustee[2]==0) trustee[2] <- 2
if (investordecision==0) trustee[2] <- 3
if (investordecision==1 && trusteedecision==1){
trustee[3] <- trustee[3] +3
investor[5] <- investor[5] + 3
}
if (investordecision==1 && trusteedecision==0){
trustee[3] <- trustee[3] +5
investor[5] <- investor[5] + 0
}
if (investordecision==0 && trusteedecision==0){
trustee[3] <- trustee[3] +1
investor[5] <- investor[5] + 1
}
if (investordecision==0 && trusteedecision==1){
trustee[3] <- trustee[3] +1
investor[5] <- investor[5] + 1
}
#assign(trustee_string, trustee, envir = globalenv())
#assign(investor_string, investor, envir = globalenv())
investors[[investor_string]] <<- investor
trustees[[trustee_string]] <<- trustee
}
trustees <- list(trustee1=c(1,0,0,0), trustee2=c(1,1,0,0))
investors <- list(investor1=c(1,1,1,1,0,0), investor2=c(1,1,1,0,0,0))
trustgame2("investor1", "trustee1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment