ZombieApocalypse_V.3

No preview image

1 collaborator

Default-person Mohini Tellakat (Author)

Tags

(This model has yet to be categorized with any tags)
Child of model ZombieApocalypse_V.2 Parent of 1 model: ZombieApocalypse_Final
Model group MAM-2013 | Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.4 • Viewed 185 times • Downloaded 13 times • Run 0 times
Download the 'ZombieApocalypse_V.3' modelDownload this modelEmbed this model

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
  aggression 
  fighting? ]

patches-own [ resource-level num-humans-on-patch ]


;;;;;;;;;;;;;;;;;;;;;
;; 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 [
    ifelse random-float 100 < food-density [ 
      ifelse pxcor > 0 or pycor < 0 
        [set resource-level random-float 10.0
          recolor-resources]
        [set pcolor gray ]];; scatter food
      [set pcolor gray] ] 
  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 black
    set heading 90 * random 4
    set energy 20 
    set infected? false 
    set fighting? false
    set affability 5
    set aggression 5
    set count-humans num-humans
  ]
end 

to infect
  ask one-of humans [ initial-infect ]
end 



;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;

to go
  humans-wander
  increase-aggression
  fight
  cluster
  ask humans [
    eat-food
    run-away
    infect-human
    human-death-natural
    fight-color
  ]
  tick
end 



;; controls the motion of the humans

to humans-wander
  ask humans[ 
    rt (random 4) * 90 
    fd 1
    set energy energy - 0.1 ]
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 and energy > 10) [
    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 <= 0) [
    ask my-links [die]
    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
          ask links [ set color black] 
          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 increase-aggression
  ask humans with [energy <= 20] [
    set aggression aggression + 0.5
  ]
end 

to gather-for-fight
  ask humans with [not infected?] [
    let x self
    ask x [ 
      ask link-neighbors [
        if aggression >= 10 [
          move-to x
        ]
      ]
    ]
    set aggression aggression + 1
  ]
end 

to fight-color
  ask humans with [not infected?] [
   ifelse fighting? 
      [set color red]
      [set color black]
  ]
end 

to fight
  ask humans with [not infected?] [
    let y self
    ask y [
      if energy >= 30 and aggression >= 10 [
        gather-for-fight
        set fighting? true
        ask other humans-here with [infected?] [
          set energy energy - (4 * num-humans-on-patch)
        ]
      ]
      set fighting? false 
    ]
  ]
end 

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
      regrow-resources
    ]
  ]
end 

;;; Zombie procedures

to eat-brains
  ask humans with [infected?] [
    ask other humans-here with [not infected?] [
      if energy < 10 [
        die 
      ]
      set energy energy + 3
    ]
  ]
end 

;; Inheritance


;;;;;;;;;;;;;;;;;;;;;;
;; 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
    if pcolor = yellow [
    set resource-level resource-level + resource-replenish-rate
    if resource-level > 10.0 [
      set resource-level 10.0
    ]]
    recolor-resources
end 

to count-humans-patch
  ask patches [
    set num-humans-on-patch (count humans-here) 
  ]
end 

There is only one version of this model, created almost 11 years ago by Mohini Tellakat.

Attached files

File Type Description Last updated
MohiniTellakat_June3.docx word ProgressReport4_Tellakat almost 11 years ago, by Mohini Tellakat Download