NetLogo.Trying使乌龟在特定的补丁颜色上死掉

时间:2014-10-26 09:08:18

标签: netlogo

所以我做了品种玩家和僵尸:

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

1 个答案:

答案 0 :(得分:3)

Variables section of the programming guide

中所述
  

乌龟可以读取和设置它所代表的补丁的补丁变量。

在您的情况下,这意味着您的僵尸可以直接检查他们所在的补丁的pcolor

if pcolor = black [ Death ]

这相当于使用patch-here的更详细的形式:

if [ pcolor ] of patch-here = black [ Death ]

您通常不需要使用坐标来识别补丁。 NetLogo有很多记者可以帮助您获得所需的补丁。例如:patch-aheadpatch-atpatch-at-heading-and-distancepatch-herepatch-left-and-aheadpatch-right-and-ahead

但是在需要使用坐标查找补丁的情况下,有patch

if [ pcolor ] of patch xcor ycor = black [ Death ]

但在你的情况下,所有这些都是不必要的。坚持简单的if pcolor = black [ Death ]

相关问题