This page was automatically generated by NetLogo 5.0.2.

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.


powered by NetLogo

view/download model file: NowakMaysBase.1.4.nlogo

WHAT IS IT?

(a general understanding of what the model is trying to show or explain)

HOW IT WORKS

(what rules the agents use to create the overall behavior of the model)

HOW TO USE IT

(how to use the model, including a description of each of the items in the Interface tab)

THINGS TO NOTICE

(suggested things for the user to notice while running the model)

THINGS TO TRY

(suggested things for the user to try to do (move sliders, switches, etc.) with the model)

EXTENDING THE MODEL

(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)

NETLOGO FEATURES

(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)

RELATED MODELS

(models in the NetLogo Models Library and elsewhere which are of related interest)

CREDITS AND REFERENCES

(a reference to the model’s URL on the web if it has one, as well as any other necessary credits, citations, and links)

CODE

globals
[
 tempScore
 bestNeighborScore
 bestNeighborStrat
]

patches-own
[
   coop?    ;; cooperate=1, defect=0
   score    ;; total of  
   newCoop?
]


;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  ca
  ifelse mandala 
  [
    ask patches [
    ifelse (pxcor = 0 and pycor = 0)
       [
         set coop? 0
         set pcolor red
       ]
       [
         set coop? 1
         set pcolor blue
       ]
    ]
  ]
  [
    ask patches [
    ifelse random 101 > percentDefectors
    [set coop? 1]
    [set coop? 0]
    ifelse (coop? = 1)
       [set pcolor blue
       ]
       [set pcolor red
       ]
    
    ]
  ]
    reset-ticks 
end


;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Go Procedures   ;;;
;;;;;;;;;;;;;;;;;;;;;;;;

to go
   
   ask patches [  
      set score 0
   ]
   playPD
   assessStrategy
   updateStrategy
   
   tick
   if stopRun and ticks >= numTicks
    [
      stop
    ]
end


to playPD
    ask patches [  
      set tempScore  0
      ifelse coop? = 0 
      [  
        ask neighbors4
        [
          if [coop?] of self = 1
             [set tempScore tempScore + b] 
        ]
      ]
      [ask neighbors4 
        [
        
          if [coop?] of self  = 1
             [set tempScore tempScore + 1] 
        ]
      ]
      set score tempScore
    ]  
end

to assessStrategy
 ask patches [  
  ask max-one-of neighbors [score]
  [
    set bestNeighborScore [score] of self
    set bestNeighborStrat [coop?] of self
  ]
  ifelse coop? = 0 
      [  
        ifelse bestNeighborScore > [score] of self [
            ifelse (bestNeighborStrat = 1)
               [set newCoop?  1
                set pcolor green] 
               [set newCoop?  0
                set pcolor red]     
            ]
           [set newCoop? 0
            set pcolor red     
            ]
      ]
      [  
        ifelse bestNeighborScore > [score] of self [
            ifelse (bestNeighborStrat = 1)
               [ set newCoop? 1
                 set pcolor blue] 
               [set newCoop?  0
                 set pcolor yellow]     
          ]
        [ set newCoop? 1
            set pcolor blue     
          ]
      ]
 ]    
         
  
end


to updateStrategy
  
    ask patches
    [  
      set coop? newCoop?
    ]
  
end


to recoverMandala 
  ifelse coop? = 0 
      [  
        ifelse bestNeighborScore > [score] of self [
            ifelse (bestNeighborStrat = 1)
               [
                set pcolor green] 
               [
                set pcolor red]     
            ]
           [
            set pcolor red     
            ]
      ]
      [  
        ifelse bestNeighborScore > [score] of self [
            ifelse (bestNeighborStrat = 1)
               [ 
                 set pcolor blue] 
               [
                 set pcolor yellow]     
          ]
        [ 
            set pcolor blue     
          ]
      ]
end







to spreadColor
  diffuse pcolor spread
  ask patches [set pcolor pcolor + Adjust]
  tick
  
  if stopRun and ticks >= numTicksMore
    [
      stop
    ]
  if ticks = 800
    [
      set spread  .8
    ]
  
  
end