Spatial Coordination Game
Model was written in NetLogo 5.0.5
•
Viewed 476 times
•
Downloaded 42 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
;;created by Ben Davies ;;for more information, see https://simulatingcomplexity.wordpress.com/2015/06/15/spatially-explicit-iterated-games-in-netlogo-an-agent-based-ht-to-john-nash/ globals [ decisions ] turtles-own [ cooperate-history defect-history ] ;;setup simulation with to setup clear-all ;;seed the decision history to even cooperation and defections for plotting purposes set decisions [0 0 0 0 0 1 1 1 1 1] ;;create 100 agents, distribute them randomly crt 100 [ setxy random-xcor random-ycor set cooperate-history [] set defect-history [] ;;set their histories of cooperation and defection to random outcomes of those decisions repeat 10 [ set cooperate-history lput (one-of (list lone-cooperator cooperate-cooperate )) cooperate-history set defect-history lput (one-of (list lone-defector defect-defect )) defect-history ] ] reset-ticks end to go ;;if strategy reaches fixation, stop if ((count turtles with [ sum cooperate-history > sum defect-history ]) / count turtles = one-of [ 0 1 ]) [ stop ] ;;if model reaches 5000 ticks, stop if ticks = 5000 [ stop ] ;;clear the decision history for this step set decisions [] ;;move agents according to random walk, then if there are any agents nearby, play a game ask turtles [ set heading random 360 fd 1 if any? other turtles in-radius search-radius [ check-game ] ] tick end to check-game ;;choices: 0 is defect, 1 is cooperate ;;agents choose their strategy based on past experience ;;determined by the sum outcomes of their previous experiences let p1choice 0 ifelse sum cooperate-history > sum defect-history [ set p1choice 1 ] [ ifelse sum cooperate-history = sum defect-history [ set p1choice one-of [ 0 1 ] ] [ set p1choice 0 ] ] let p2 one-of other turtles in-radius search-radius let p2choice 0 ifelse [ sum cooperate-history ] of p2 > [ sum defect-history ] of p2 [ set p2choice 1 ] [ ifelse [ sum cooperate-history ] of p2 = [ sum defect-history ] of p2 [ set p2choice one-of [ 0 1 ] ] [ set p2choice 0 ] ] ifelse p1choice = 1 [ ;;Both cooperate ifelse p2choice = 1 [ set cooperate-history lput cooperate-cooperate cooperate-history ask p2 [ set cooperate-history lput cooperate-cooperate cooperate-history ] ] ;;Player 1 cooperates, Player 2 defects [ set cooperate-history lput lone-cooperator cooperate-history ask p2 [ set defect-history lput lone-defector defect-history ] ] ] [ ;;Player 1 defects, Player 2 cooperates ifelse p2choice = 1 [ set defect-history lput lone-defector defect-history ask p2 [ set cooperate-history lput lone-cooperator cooperate-history ] ] ;;Both defect [ set defect-history lput defect-defect defect-history ask p2 [ set defect-history lput defect-defect defect-history ] ] ] ;;drop the oldest memory if length cooperate-history > 10 [ set cooperate-history remove-item 0 cooperate-history ] if length defect-history > 10 [ set defect-history remove-item 0 defect-history ] ask p2 [ if length cooperate-history > 10 [ set cooperate-history remove-item 0 cooperate-history ] if length defect-history > 10 [ set defect-history remove-item 0 defect-history ] ] ;;record the decisions for plotting set decisions lput p1choice decisions set decisions lput p2choice decisions end
There are 2 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Spatial Coordination Game.png | preview | Preview for 'Spatial Coordination Game' | over 8 years ago, by benjamin davies | Download |
This model does not have any ancestors.
This model does not have any descendants.