Zombie infection 2 V1.5

Zombie infection 2 V1.5 preview image

1 collaborator

Default-person xarty11 ulep11 (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.5 • Viewed 767 times • Downloaded 32 times • Run 0 times
Download the 'Zombie infection 2 V1.5' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This is a simulation of a town in which a zombie infection arises. The first version was a moderately faithful rewrite of Kevan Davis' Zombie Infection Simulation in NetLogo; since then we've added a lot of functionality.

HOW IT WORKS

Zombies are green, shamble around very slowly and change direction randomly and frequently unless they can see something moving in front of them, in which case they start walking towards it. After a while they get bored and wander randomly again.

If a zombie finds a human on the same patch, it infects them; the human immediately joins the ranks of the undead.

Humans are lightish gray and walk five times as fast as zombies, changing direction when they run into a wall, and sporadically otherwise. If they see a zombie in front of them, they turn around and panic.

Panicked humans are pink and run twice as fast as other humans. If a human sees another panicked human, it starts panicking as well. A panicked human who has seen nothing to panic about for a while will calm down again.

The military are red and move as regular humans do, unless they see a zombie or panicked human, which they will run towards. A member of the military will kill any zombies on a patch they walk into. Further options are open to the military if authorised:

  • they may detonate a pocket nuke if they see sufficiently many zombies, immolating all life (undead included) in the blast radius and damaging buildings.
  • they may recruit ordinary humans, up to the originally specified size of the force.

HOW TO USE IT

Press SETUP to create and populate a new city.
Press SETUP-BEINGS to place the beings while retaining the current city.
GO, as usual, runs the model. STEP runs it for one step.

Parameters:

Town parameters (only takes effect on SETUP)
NUM-SQUARES: number of open areas in the city

Initial populations (only takes effect on SETUP or SETUP-BEINGS)
NUM-HUMANS: number of humans
NUM-ZOMBIES: number of zombies
NUM-MILITARY: number of military (changing RECRUIT-%AGE looks at this in real time, though)

Perception
VISION-DISTANCE: baseline distance which creatures can sense (see/hear/smell/...) other creatures in
ZOMBIE-ACUTENESS: multiplier to this distance for zombies
VISION-ANGLE: angle of the sensory cone

Human-specific behaviour
PANIC-DURATION: how long humans panic upon seeing something frightening
BREEDING-%AGE: how likely two humans meeting are to procreate (immediately!)

Zombie-specific behaviour
WALL-BREAK-%AGE: how likely a zombie sensing something across a wall is to smash through
NOM-TIME: how long a zombie takes to consume its prey's brains
ZOMBIES-AGE?: if on, zombies become decrepit and eventually cease to exist with the passage of time
ZOMBIE-LIFESPAN: if aging is on, how long a new zombie can expect to live, unfed
NOM-BOOST: if aging is on, the extension catching a victim provides to a zombie's lifespan, as a fraction of ZOMBIE-LIFESPAN

Military-specific behaviour
RECRUIT-%AGE: how likely the military are to recruit humans into the military. The military will never expand past NUM-MILITARY members (one imagines they have a finite supply of guns, or badges, or whatnot.)
NUKES-AUTHORIZED?: can the military use their pocket nukes?
NUKE-RADIUS: the blast radius of pocket nukes
NUKE-DAMAGE: how damaging the nukes are to buildings (they always annihilate all creatures in their radius)
NUKE-DISTANCE:
NUKE-MINIMUM-KILL: military will only use pocket nukes if they think there are NUKE-MINIMUM-KILL zombies within NUKE-DISTANCE.

SIGNIFICANT DIFFERENCES FROM KEVAN'S

The model of space is the standard NetLogo model, in which space and direction are both continuous. Thus, for instance, it's more reasonable for humans to keep
running in straight lines when nothing is in their way; they don't miss entrances to small passages or cluster as much as they would in the discrete grid-based model.

Beings' fields of vision are cones with 90 degree width instead of just the lines directly ahead. These fields of vision go through walls (I guess the beings can hear, or smell, or something).

The city wraps around unless you change the model topology; again, this is more natural in NetLogo than it might be in proce55ing.

Arbitrarily many beings may occupy one patch.

The city is carved out differently: although it has the same general feel, more types of passages can occur, for instance zig-zags:

 *****************
                 *
                 *
                 *
                 *****************

Beings only look ahead of themselves every fifth time step. This was done to speed the model up, and appears to have no significant effects on the simulation.

THINGS TO NOTICE

Infection takes place much more slowly, in terms of simulation timesteps, than in the original model.

In zombie-dominated areas of the city, the zombies tend to form into lines (in the original model, we instead observe blobs).

THINGS TO TRY

In general: when do humans win, when do zombies win? Find combinations of settings that make it a fair fight. (E.g. does zombie wall-breaking actually help the zombie side? Do zombies do better when they sit in wait in their corridors, or destroy them digging out to where the brains are?)

What population density does panic need to be self-sustaining?

Make everyone a zombie, let zombies break walls 100% of the time, and watch the zombie streamers.

Play with NetLogo perspective features like watch and follow.

Resize the city, using the Edit button on the city display. This will probably require adjusting the numbers in the setup-town procedure to get the same overall proportion of open space.

EXTENDING THE MODEL

You've seen at least as many zombie movies as I have...

These extensions are more like bug-fixes:

  • Ensure that there are no completely isolated spaces without entrances or exits when the city is created.
  • Make the walls actually opaque? (This will probably be a mess, since there is no support for this among the NetLogo agentset reporters like in-cone.)

And, of course, it would be nice to make it run faster.

NETLOGO FEATURES

The tunnels in the city are carved by a dedicated breed of turtle (an initial attempt to generate them with patch agentsets proved horribly slow).

I like the way beings reorient themselves after hitting a wall -- they can even follow tunnels with no special case movement rules.

Building damage after a nuke is implemented by having each patch in the blast radius
change to open space with a constant probability, otherwise change its state to that of a random neighbour in a small radius. This nicely and quickly simulates rubble getting blown about.

Beings never move by more than distance 1 at a time, to prevent them from jumping through walls.

CREDITS AND REFERENCES

Alex Fink and Sai Emrys, this version
AF, the first version, Jan 2006

Kevan Davis' original Zombie Infection Simulation, version 2.3:
http://kevan.org/proce55ing/zombies/

NetLogo zombie simulators seem to've become popular in these last few years;
one might also check out Asymptote's one,
http://ccl.northwestern.edu/netlogo/models/community/ZombieInfection2
and Marcel Jira's ones,
http://web.student.tuwien.ac.at/~e0250890/netlogo/ .

WHAT NEW

V1.5

+new bar plot

V1.4

+New ride random

V1.3

+New ride 2 breed humans/zombie

V1.2 *change shape face

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [turn-probability]

;; diggers are used only for setup
breed [ diggers ]
breed [ humans ]
breed [ zombies ]
breed [ military ]

humans-own [panic-time] 
zombies-own [chasing-time lifespan ]
patches-own [fade-time]
turtles-own [generation paralysis-time kills]

to go
  set-current-plot "Population vs. time"
  set-current-plot-pen "Zombies"
  plot count zombies
  
  set-current-plot-pen "Military"
  plot count military
  
  set-current-plot-pen "Humans"
  plot count humans
  
  set-current-plot "Zombie lifespan"
  plot ifelse-value any? zombies [ mean [lifespan] of zombies / zombie-lifespan ] [0]

  ask patches with [fade-time > 0] [
    set fade-time fade-time - 1
    if-else fade-time <= 0 [ set pcolor black ] [ set pcolor scale-color red fade-time 0 120 ]
  ]

  ask military with [paralysis-time <= 0] [
    if (who - ticks) mod 5 = 0 [
      let beings-seen turtles in-cone vision-distance vision-angle with [self != myself] 
      ;; run towards zombies
      ifelse any? beings-seen with [breed = zombies] [
        let target one-of beings-seen with [breed = zombies]
        face target
        step 1
      ] [
        ;; or failing that, towards the most panic
        if any? beings-seen with [breed = humans and panic-time > 0] [
          let target max-one-of beings-seen with [breed = humans and panic-time > 0] [panic-time]
          face target 
          step 1
        ]
      ]
      
      if nukes-authorized? [
        let nuke-zone-seen turtles in-cone nuke-distance vision-angle with [breed = zombies]
        if count nuke-zone-seen > nuke-minimum-kill [
          detonate-nuke
        ]
      ]
    ]
    
    step-turnily 1
    
    set kills kills + count zombies-here
    
    ask zombies-here [ die ]
    
    ;; Military will recruit civilians back up to their starting population
    ;; aka "Hey you, here's a gun and a pocket nuke. Have fun." 
    if random-float 100.0 < recruit-%age and  count military < num-military and any? humans-here [
      ask one-of humans-here [
        set breed military
        set color red
        set generation [generation] of myself + 1
      ]
    ] 
  ]

  ask zombies with [paralysis-time <= 0] [
    ifelse chasing-time > 0 [
      set chasing-time chasing-time - 1
    ] [
      if random 4 = 0 [set heading random 360]
    ]
    
    if (who - ticks) mod 5 = 0 [
      let beings-seen turtles in-cone (vision-distance * zombie-acuteness) vision-angle with [self != myself] 
      if any? beings-seen [
        let target one-of beings-seen
        face target
        set chasing-time 20
      ]
    ]
    
    ;; Zombies can break down walls if they're following something
    corrode-step 0.2 (random-float 100 < wall-break-%age and chasing-time > 0)
    
    if zombies-age? [
      set lifespan lifespan - 1
      if lifespan <= 0 [ die ]
    ]
    
    if any? turtles-here with [breed != zombies]
    [ 
      set kills kills + count turtles-here with [breed != zombies]
      ask turtles-here with [breed != zombies] [
        set paralysis-time nom-time
        set breed zombies
        set color green
        set shape "face neutral"
        set lifespan zombie-lifespan 
        set generation [generation] of myself + 1
      ]
      set lifespan lifespan + zombie-lifespan * nom-boost
      set paralysis-time nom-time
    ]
  ]
  
  ask humans with [paralysis-time <= 0] [
    step-turnily 1
    if panic-time > 0 [
      set shape "face happy"
       set panic-time panic-time - 1
       if panic-time = 0 [set color white - 4]
       step 1
    ] 

    if (who - ticks) mod 5 = 0 [
      let beings-seen turtles in-cone vision-distance vision-angle with [self != myself and (breed = zombies or (breed = humans and panic-time > 0))] 
      if any? beings-seen [
        lt 157.5 + random-float 45
        set shape "face sad"
        set color magenta + 3
        
        ;; panicked humans are infectious
        if any? beings-seen with [breed = humans and panic-time > 0] [ 
          set panic-time (max [panic-time] of beings-seen with [breed = humans])
        ]
        ;; oh noes teh zombie
        if any? beings-seen with [breed = zombies] [ set panic-time panic-duration ]
      ]
      
    ]
    
    if panic-time <= 0 and random-float 100 < breeding-%age and any? humans-here [
      hatch 1 [
        set generation [generation] of myself + 1
      ]
    ]
  ]
  
  ask turtles with [paralysis-time > 0] [
    set paralysis-time paralysis-time - 1
  ]
    
  tick
end 

to detonate-nuke 
  ask patches in-radius nuke-radius [ 
    ifelse random-float 1 > nuke-damage and ([pcolor] of one-of patches in-radius 3) != black [ set pcolor gray - 3 ] [ set fade-time 60 ]
  ]
  ask turtles in-radius nuke-radius [ die ]
end 

;; Step without running into things.  dist, the distance to step, should not
;; exceed 1, else the turtle might jump through a wall.  

to step [dist] ;; kludge for default parameter
  corrode-step dist false
end 

to step-turnily [dist]
  corrode-step dist false
  if random-float 1 < turn-probability [ lt random-normal 0 60 ]
end 

to corrode-step [dist corrode]
  if [pcolor] of patch-ahead dist != black [
    ;; Turn so that we're facing parallel to the wall, ie. find the black neighbouring
    ;; patch closest to where we would have gone (at distance 1), and turn to face it.
    if-else corrode [
      ask patch-ahead dist [ set pcolor black ]
    ][
      let x dx + xcor
      let y dy + ycor
      if not any? neighbors with [pcolor = black] [die]
      face min-one-of neighbors with [pcolor = black] [distancexy x y]
    ]
  ]
  fd dist
end 

;; doesn't quite always uninfect, if num-zombies was increased

to uninfect
  ;; Reduce the number of zombies to num-zombies.  
  ask zombies with [who >= num-zombies] [
    set breed humans
    set color magenta
  ]
  ask humans with [who < num-zombies] [
    set breed zombies
    set color green     
  ]
end 

to setup
  setup-town
  setup-beings

  ;; globals
  set turn-probability 1 / 60.0
end 

to setup-beings
  ct
  ;; this stuff is in this function just so it always happens
  clear-all-plots
  
  reset-ticks
  
  ;; Zombies get the earliest who numbers; we use this elsewhere.
  ;; Make sure the beings are on non-built squares.  
  create-zombies num-zombies [
    set color green
    set lifespan zombie-lifespan
    set shape "face neutral"
    set size 0.5
    set pen-size 0.5
   
  ]

  create-humans num-humans [
    set color white - 4
    set shape "face happy"
    set size 0.5
    set pen-size 0.5
  ]
  
  create-military num-military [
    set color red
    set shape "face neutral"
    set size 0.5
    set pen-size 0.5
  ]
  
  ask turtles [
    setxy random-float world-width random-float world-height        
    set heading random-float 360
    set paralysis-time 0
    set generation 0
    set kills 0
    while [pcolor != black] [fd 1]
  ]
end 

to setup-town
  cp
  ask patches [
    set pcolor gray - 3
    set fade-time 0
  ]

  ;; Make the alleyways.  Instead of the rectangle-placing approach, which proves slow, 
  ;; let a special kind of turtle dig them.  
  ;; The number of diggers here and later will need changing if the screen size is changed.
  ct
  create-diggers 154;; 112 

  ;; Set the diggers up in pairs facing away from each other, so we don't get dead end passages
  ask diggers with [who mod 2 = 0] [
    setxy random-float world-width random-float world-height        
    set heading 90 * random 4
  ]
  ask diggers with [who mod 2 = 1] [
    setxy [xcor] of turtle (who - 1) [ycor] of turtle (who - 1)
    set heading 180 + [heading] of turtle (who - 1)
    fd 1
  ]

  ask diggers [
    while [pcolor != black] [
      set pcolor black
      fd 1
      if random-float 1 < (1 / 30) [lt 90 + 180 * random 2]
    ]
  ]
  
  ;; Make the squares, by getting a few diggers to dig them out.  
  ct
  create-diggers num-squares [
    setxy random-float world-width random-float world-height
    let xsize 2 + random 60
    let ysize 2 + random 60
    foreach n-values xsize [?] [
      let x ?
      foreach n-values ysize [?] [ask patch-at x ? [set pcolor black]]
    ]
  ]
  ;hello
  ct
end 

;; updated 2014

There is only one version of this model, created over 3 years ago by xarty11 ulep11.

Attached files

File Type Description Last updated
Zombie infection 2 V1.5.png preview Preview for 'Zombie infection 2 V1.5' over 3 years ago, by xarty11 ulep11 Download

This model does not have any ancestors.

This model does not have any descendants.