所以我做了品种玩家和僵尸:
breed [zombies zombie]
breed [players player]
如果它走到一个黑色斑点(坑),我想杀死一个僵尸。
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
答案 0 :(得分:3)
如Variables section of the programming guide:
中所述乌龟可以读取和设置它所代表的补丁的补丁变量。
在您的情况下,这意味着您的僵尸可以直接检查他们所在的补丁的pcolor
:
if pcolor = black [ Death ]
这相当于使用patch-here
的更详细的形式:
if [ pcolor ] of patch-here = black [ Death ]
您通常不需要使用坐标来识别补丁。 NetLogo有很多记者可以帮助您获得所需的补丁。例如:patch-ahead
,patch-at,patch-at-heading-and-distance
,patch-here
,patch-left-and-ahead
和patch-right-and-ahead
。
但是在需要使用坐标查找补丁的情况下,有patch
:
if [ pcolor ] of patch xcor ycor = black [ Death ]
但在你的情况下,所有这些都是不必要的。坚持简单的if pcolor = black [ Death ]
。