ZombieApocalypse_V.2
No preview image
Model was written in NetLogo 5.0.4
•
Viewed 259 times
•
Downloaded 15 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
;;;;;;;;;;;;;;;;;; ;; Declarations ;; ;;;;;;;;;;;;;;;;;; globals [ count-zombies count-humans run-number ;; counter used to keep the model running for a little ;; while after the last turtle gets infected delay ] breed [ humans human ] ;; infected? - checks to see whether a human is infected ;; energy - human energy level ;; affability - how friendly the human is (helps determine whether they will help others) humans-own [ energy affability infected? friends nearest-neighbor ] patches-own [ resource-level ] ;;;;;;;;;;;;;;;;;;;;; ;; Setup Functions ;; ;;;;;;;;;;;;;;;;;;;;; ;; clears the plot too to setup-clear clear-all set run-number 1 setup-world end ;; note that the plot is not cleared so that data ;; can be collected across runs to setup-keep clear-turtles clear-patches set run-number run-number + 1 setup-world end to setup-world set-default-shape humans "person" ask patches [ ;; give grass to the patches, color it shades of green set resource-level random-float 10.0 recolor-resources ;; change the world green ] set delay 0 create-some-humans reset-ticks end to create-some-humans create-humans num-humans [ setxy random-pxcor random-pycor ;; put androids on patch centers set color gray set heading 90 * random 4 set energy 20 set infected? false set affability 1 set count-humans num-humans ] end to infect ask one-of humans [ initial-infect ] end ;;;;;;;;;;;;;;;;;;;;;;; ;; Runtime Functions ;; ;;;;;;;;;;;;;;;;;;;;;;; to go humans-wander ask humans [ eat-food cluster run-away infect-human fight human-death-natural ] tick end ;; controls the motion of the humans to humans-wander ask humans[ rt (random 4) * 90 fd 1 set energy energy - 0.7 ] end to initial-infect if not infected? [ set infected? true set color green set affability 0 set energy 30 ] end to infect-human ask other humans-here [ if not infected? and (energy < 15) [ set infected? true set color green set affability 0 set energy 30 ask my-links [die] ] ] ;;set count-zombies count-zombies + 1 ;;set count-humans count-humans - 1 ] end to human-death-natural if not infected? and (energy < 8) [ die ] ;; set count-humans count-humans - 1] end ;;;;;;;;;;;;;;;;;;;;;;; ;;; Human Behaviors ;;; ;;;;;;;;;;;;;;;;;;;;;;; to cluster ;; turtle procedure ask humans with [not infected?] [ let x self ask humans-on neighbors [ if not infected? [ let aff-h [affability] of self if affability = aff-h [ create-link-with x set affability affability + 1 ] if affability < aff-h [ avoid ] ] ] ] end to avoid ;; android procedure let candidates patches in-radius 1 with [ not any? humans-here with [ infected? ] ] ifelse any? candidates [ face one-of candidates ] [ rt (random 4) * 90 ] end to run-away ask humans with [not infected?] [ ask humans-on neighbors [ if infected? [ rt (random 4) * 90 fd 2 ] ] ] end to fight ask humans with [not infected?] [ if energy >= 30 [ ask other humans-here with [infected?] [ set energy energy - 4 ] ] ] end ;; sheep procedure, sheep eat grass to eat-food ask humans with [not infected? ] [ if ( resource-level >= energy-gain-from-food ) [ ;; increment the moose's energy set energy energy + energy-gain-from-food ;; decrement the grass set resource-level resource-level - energy-gain-from-food recolor-resources ] ] end to eat-brains ask humans with [infected?] [ ask other humans-here with [not infected?] [ die ] ] end ;;;;;;;;;;;;;;;;;;;;;; ;; Patch procedures ;; ;;;;;;;;;;;;;;;;;;;;;; ;; recolor the grass to indicate how much has been eaten to recolor-resources ;; set pcolor scale-color green grass 0 20 set pcolor scale-color yellow (10 - resource-level) -10 20 end ;; regrow the grass to regrow-resources ask patches [ set resource-level resource-level + resource-replenish-rate if resource-level > 10.0 [ set resource-level 10.0 ] recolor-resources ] end
There is only one version of this model, created almost 12 years ago by Mohini Tellakat.
Attached files
No files