【问题标题】:NetLogo.Trying to make turtle on a specific patch color dieNetLogo. Trying to make turtle on a specific patch color die
【发布时间】:2014-10-26 09:08:17
【问题描述】:

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

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

【问题讨论】:

  • 您应该编辑您的问题并进行文本和代码格式设置。

标签: netlogo


【解决方案1】:

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 ]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-01
    • 2022-12-28
    • 2022-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-01
    • 2022-12-02
    相关资源
    最近更新 更多