1

I'm currently working on a zombie apocalypse simulation in NetLogo 2D. In my current simulation, when the zombies collide with humans the humans have a 100% chance to turn into a zombie. I would like to change this so that I can use a slider to set the conversion rate - for example if I have a rate of 50% on my slider, then when the zombies collide with humans there's a 50% chance they would turn into a zombie, otherwise kill the attacking zombie.

This is how I have currently setup my project, the way I've done this so far is to detect when they collide, and set the humans health to -1, and then made an if statement that says if the health is below 1, to make them a zombie.

I would appreciate any help in the right direction as I've spent time pondering about this and haven't come up with any solution.

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
Louis K
  • 11
  • 2

1 Answers1

1

Making minimal adjustments to your code you could substitute the set health -1 to

if random 100 < conversion_probability [ set health 0 ]

where conversion_probability is a slider going from 0 to 100, as you said in the question.

I also want to point out that you could detect walls like this

to detect_wall
  if [solid] of patch-ahead 2
  [
    face one-of patches in-radius 2 with [not solid]
  ]
end

doing left x and then right x only makes the turtle turn to the left and then face back where it was originally facing, unless it sees a zombie it won't change the behavior of the humans all that much.

Matias Agelvis
  • 951
  • 2
  • 11
  • 22