NetLogo To make a turtle on a specific patch color
So, I created a player and a zombie breed:
breed [zombies zombie]
breed [players player]
I would like to kill the zombie if it fits the black patch (pit).
to go
ask zombies
[
;set heading (heading + 45 - (random 90))
let closest-player min-one-of players[distance myself]
set heading towards closest-player
forward 1
;if xcor = pcolor black [Death] I have a lot to learn for netlogo syntax
;if ycor = pcolor black [Death] these lines are to give an Idea of what I'm trying to do.
]
end
to Death ;; turtle procedure
set shape "skull"
set color white
set heading 0
end
source to share
As described in the Variables section in the programming guide :
the turtle can read and set the patch variables of the patch it is on.
In your case, this means that your zombies can directly check the pcolor
patch they are in:
if pcolor = black [ Death ]
This is the equivalent of a more verbose form with patch-here
:
if [ pcolor ] of patch-here = black [ Death ]
You often don't need to use coordinates to define a patch. NetLogo has many reporters who can help you get the patch you want. For example: patch-ahead
, patch-AT , patch-at-heading-and-distance
, patch-here
, patch-left-and-ahead
and patch-right-and-ahead
.
But in cases where you need to find a patch using coordinates patch
:
if [ pcolor ] of patch xcor ycor = black [ Death ]
But none of this is necessary in your case. Keep it simple if pcolor = black [ Death ]
.
source to share