ZombieApocalypse_Final
No preview image
Model was written in NetLogo 5.0.4
•
Viewed 475 times
•
Downloaded 76 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 [ run-number ;; counter used to keep the model running for a little ;; while after the last turtle gets infected delay ] breed [ humans human ] humans-own [ energy ;; human energy level affability ;; how friendly the human is (helps determine whether they will group with others) infected? ;; boolean - are they infected with the zombie virus or not? aggression ;; measures likelihood of fighting zombies fighting? ;; boolean - are they currently fighting or not ] patches-own [resource-level num-humans-on-patch is-growing-food? ] ;;;;;;;;;;;;;;;;;;;;; ;; 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 ;; scatters food patches across the world in 3/4 quadrants. The patches also have varying food density levels to setup-world set-default-shape humans "person" ask patches [ ifelse random-float 100 < food-density [ ifelse pxcor > 0 or pycor < 0 [set pcolor yellow set is-growing-food? true] [set pcolor gray ]] [set pcolor gray] ] set delay 0 create-some-humans create-some-zombies reset-ticks end ;; creates humans and gives them certain properties to create-some-humans create-humans num-humans [ setxy random-pxcor random-pycor ;; put humans on patch centers set color black set heading 90 * random 4 set energy 20 set infected? false set fighting? false set affability 5 set aggression 5 ] end ;; for infect button - user initially infects a few humans with the zombie virus to create-some-zombies create-humans num-zombies [ setxy random-pxcor random-pycor set heading 90 * random 4 set infected? true set color green set affability 0 set energy 30 set aggression 10 ] end ;;;;;;;;;;;;;;;;;;;;;;; ;; Runtime Functions ;; ;;;;;;;;;;;;;;;;;;;;;;; to go humans-wander increase-aggression reproduce fight ;; Humans will cluster together if they have the same affability level (if they are nice to each other, they form links/ ;; groups) and will avoid each other if one person is less nice than the other. if cluster? [ ask humans with [not infected?] [ let x self ask humans-on neighbors [ if not infected? [ let aff-h [affability] of x if aff-h = affability [ create-link-with x ask links [ set color blue] set affability affability + 1 ] if affability < aff-h [ avoid ] ] ] ] ] eat-food run-away infect-human human-death-natural fight-color regrow-resources set num-zombies count humans with [infected?] set num-humans count humans with [not infected?] if num-zombies = 0 or num-humans = 0 [ stop ] tick end ;; controls the general motion of the humans to humans-wander ask humans[ rt (random 4) * 90 fd 1 if not infected? [ set energy energy - 0.1 ]] end ;;;;;;;;;;;;;;;;;;;;;;; ;;; Human Behaviors ;;; ;;;;;;;;;;;;;;;;;;;;;;; ;; If a human's energy runs to 0, they die automatically. to human-death-natural ask humans [ if not infected? and (energy <= 0) [ die set num-humans num-humans - 1] ] end ;; Humans turn around and avoid each other if they encounter each other. Used in the clustering behavior. to avoid 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 ;; Humans will run-away from a zombie by moving a farther distance (essentially a sort of jump away from the zombies ;; if they are nearby) to run-away ask humans with [infected?] [ ask humans-on neighbors [ if not infected? [ rt (random 4) * 90 fd 2 ] ] ] end ;; If humans are hungry, they get cranky and more aggressive. to increase-aggression ask humans with [energy <= 20 and not infected?] [ set aggression aggression + 0.5 ] end ;; If a human is strong enough to fight zombies, he calls over the people he is linked to in order to kill the zombie ;; with help. Humans also get more aggressive when gathering for a fight, like they are feeding off each other's energy. to gather-for-fight ask humans with [not infected?] [ let x myself ask link-neighbors [ move-to x set fighting? true ask humans-here with [infected?] [ set energy energy - num-humans if energy <= 0 [die]] ] set aggression aggression + 1 ] end ;; makes it easier to see who is fighting to fight-color ask humans with [not infected?] [ if fighting? [set color red] ] end ;; Fight behavior for humans - gathers up friends and tries to kill a zombie. ;;and energy >= 30 and aggression >= 6 to fight ask humans with [not infected? and energy >= 30 and aggression >= 6] [ if any? humans-here with [infected?] [ ifelse cluster? [gather-for-fight] [set fighting? true ask humans-here with [infected?] [ die ] ] ] ] end ;; In order to keep their energy up, humans have to keep eating food. to eat-food ask humans with [not infected? ] [ if pcolor = yellow [ set pcolor gray set energy energy + energy-gain-from-food ;; increment human energy level ] ] end to reproduce if reproduce? [ ask humans with [not infected?] [ let x self if energy >= 100 [ set energy energy - 50 ;; reproduction transfers energy hatch 1 [ set energy 20 set affability [affability] of x set aggression [aggression] of x ] ;; to the new agent ] ] ] end ;;; Zombie procedures ;; Zombies have to eat too, but instead of food, they feast on fresh human brains to eat-brains ask humans with [infected?] [ ask other humans-here with [not infected?] [ if energy < 10 [ die ] set energy energy + 3 ] ] end ;; If a human encounters a zombie and their energy level is between a certain threshold, then the human gets infected by ;; the virus to infect-human ask humans with [infected?] [ ask other humans-here [ if not infected? and (energy < 15 and energy > 10) [ set infected? true set color green set affability 0 set energy 30 ask my-links [die] ] ] ] end ;;;;;;;;;;;;;;;;;;;;;; ;; Patch procedures ;; ;;;;;;;;;;;;;;;;;;;;;; ;to resource-level-energy ; set energy resource-level ;end ; ;;; recolor the food to indicate how much has been eaten ;to recolor-resources ;set pcolor scale-color yellow (10 - resource-level) -10 20 ;end ;; regrow the food to regrow-resources ask patches with [pcolor = gray] [ if is-growing-food? != 0 [ if (random-float 100 < resource-replenish-rate) and (pxcor > 0 or pycor < 0) [ set pcolor yellow ] ] ] end
There are 2 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Tellakat Final Poster.pptx | powerpoint | Poster Session Poster | over 11 years ago, by Mohini Tellakat | Download |
Tellakat_Mohini_FinalProjectPaper and Data.zip | data | Final Paper, data, and graphs | over 11 years ago, by Mohini Tellakat | Download |
Parent: ZombieApocalypse_V.3
This model does not have any descendants.