I am not sure what you are trying to do in your plot-manhattan-distance
procedure. It seems like a complicated approach to something that should be relatively simple, but maybe I misunderstood your purpose. Here is how I would approach the whole problem:
globals [
zombie
human
]
to setup
clear-all
ask n-of 2 patches [ sprout 1 ]
set human turtle 0
ask human [ set shape "person" ]
set zombie turtle 1
ask zombie [ pen-down ]
end
to go
ask human [ flee zombie ]
ask zombie [ pursue human ]
end
to pursue [ target ]
face target
set heading first sort-by [abs (?1 - heading) < abs (?2 - heading)] [0 90 180 270]
fd 1
end
to flee [ pursuer ]
face pursuer
rt 180
fd 0.5
end
The meat is in the pursue
procedure. Since the zombie cannot predict where the human is going to go, it is just trying to move in its general direction. It starts by facing the human directly (with the handy NetLogo face
primitive). But since it is presumably only allowed to move in one of the four cardinal directions, it must choose the one that is the most desirable, i.e.: the one that is the least different from its current (ideal) heading. This is what the sort-by [abs (?1 - heading) < abs (?2 - heading)] [0 90 180 270]
expression does: it sorts the list of directions by comparing their absolute difference with the current heading. The first item of this sorted list will be the one with the smallest difference, and thus, the one that the zombie needs to use.
In the current implementation, the human just tries to move away from the zombie, but you could easily replace that with player control code.