Reputation: 147
We are working on a netlogo model in which fishes are hunted and eaten by shark. It is built on the flocking 3d - alternate model.
At the moment we have the sharks able to follow the fishes, but we can't figure out how to make them eat them. Right now the fishes die when they touch each other:
ask fishes
[ flock
;; if we've hit something
;; we're a goner
if pcolor != black [ hatch-dead-fishes 1
[ bk 1 ]
die ]
]
What we want is something like:
ask fishes
[ flock
if xcor and ycor and zcor of shark == xyz cor of a fish
[ hatch-dead-fishes 1
[ bk 1 ]
die ]
]
Now clearly we don't know how to properly write this code. We also noticed that when a fish dies it doesn't actually get removed from the screen. Anyone know
Any help would be welcome! Thanks :)
Upvotes: 2
Views: 1647
Reputation: 2096
Your fish are most likely disappearing they are just being replaced by hatch-dead-fish.
to have the sharks eat the fish I have found that
ask sharks [ask fish-here [die]]
(assuming fish and sharks are two breeds if they are not you should make them two breeds)
changing your code to do about the same thing is much longer
ask fishes
[ flock
if pxcor = [pxcor] of shark and pycor = [pycor] of shark and pzcor = [pzcor] of shark
[ hatch-dead-fishes 1
[ bk 1 ]
die ]
]
I took the liberty of changing the coordinates to patch rather than turtles because it is really hard to get a collision on floating-points
Upvotes: 3