Spatial Prisoner's Dilemma

Spatial Prisoner's Dilemma preview image

1 collaborator

Default-person David Sousa (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.1.0 • Viewed 186 times • Downloaded 11 times • Run 0 times
Download the 'Spatial Prisoner's Dilemma' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

patches-own [
  cooperate?
  old-cooperate?
  score
  color-class
  Prob
]

to setup
  clear-all
  ask patches [setup-cooperation false update-color]
  ask n-of (cooperators * (count patches)) patches [setup-cooperation true update-color]
  reset-ticks
  update-plot
end 

to setup-1-at-the-center
  clear-all
  ask patches [
    setup-cooperation true
    update-color
  ]
  ask patch 0 0 [
    setup-cooperation false
    update-color
  ]
  reset-ticks
  update-plot
end 

to setup-cooperation [value]
  set cooperate? value
  set old-cooperate? value
end 

to go
  ask patches [update]
  tick
  update-plot
end 

to-report neighborsN
  ifelse n-neighbors = 8 [report (patch-set neighbors self)][report (patch-set neighbors4 self)]
end 

to update
  ask neighborsN [
    ifelse cooperate?
    [set score (count neighborsN with [cooperate? = true])]
    [set score (count neighborsN with [cooperate? = true]) * b]
    set old-cooperate? cooperate?
  ]
  ifelse update-rule = "deterministic" [
    if [score] of max-one-of neighborsN [score] > score [
      set cooperate? [cooperate?] of max-one-of neighborsN [score]
    ]
  ][
    let numberp sum (map [ ?1 -> ?1 ^ m ] [score] of neighborsN with [cooperate?])
    let numberq sum (map [ ?1 -> ?1 ^ m ] [score] of neighborsN)
    ifelse numberq = 0 [set Prob 0][set Prob (numberp / numberq)]
    ifelse random-float 1 <= Prob [set cooperate? true][set cooperate? false]
  ]
  update-color
end 

to update-color
  ifelse old-cooperate?
    [ifelse cooperate?
      [set pcolor blue
       set color-class 1]
      [set pcolor yellow
       set color-class 3]
    ]
    [ifelse cooperate?
      [set pcolor green
       set color-class 4]
      [set pcolor red
       set color-class 2]
    ]
end 

to update-plot
  set-current-plot "Cooperation/Defection numbers"
  plot-histogram-helper "cc" blue
  plot-histogram-helper "dd" red
  plot-histogram-helper "cd" green
  plot-histogram-helper "dc" yellow
end 

to plot-histogram-helper [pen-name color-name]
  set-current-plot-pen pen-name
  histogram [color-class] of patches with [pcolor = color-name]
end 

There is only one version of this model, created about 4 years ago by David Sousa.

Attached files

File Type Description Last updated
Spatial Prisoner's Dilemma.png preview Preview for 'Spatial Prisoner's Dilemma' about 4 years ago, by David Sousa Download

This model does not have any ancestors.

This model does not have any descendants.