试图获得海龟品种,以避免特定颜色的补丁

时间:2014-11-08 17:58:58

标签: netlogo

; num-Holes实际上是一个全局变量。我试图让他们避免黑色斑点(地板上的洞)

if any? Patches in-Radius num-Holes with[pcolor = black] 
[
set heading (towards min-one-of num-Holes[distance myself]) + 180 - random 10 + random 10   
]

我正试图让我的僵尸试图避免黑色补丁 我知道netlogo不会接受全球'num-Holes'所以我怎么能让它看到并避免补丁呢? 这里有更广泛的代码范围,使我的问题更加清晰。

     to go
   ask zombies
   [
   ;set heading (heading + 45 - (random 90))
    let closest-player min-one-of players[distance myself]
    set heading towards closest-player
    ;wait 1
    forward 1
        if pcolor = black [Death]
        if pcolor = black [Death]

    ;num-Holes is actually a global variable. I'm trying to get them to avoid the black patches(holes in the floor)
    if any? Patches in-Radius num-Holes with[pcolor = black] 
    [
    set heading (towards min-one-of zombies[distance myself]) + 180 - random 10 + random 10   
    ]   ]
end

请,谢谢你:)

2 个答案:

答案 0 :(得分:2)

在编写代码时,您似乎已将num-Holes设置为代理程序集。 (补丁?)那么你想把第一行改为if any? (num-Holes in-radius 5)

您可能还想查看NetLogo用户社区模型中的僵尸模型。

如果num-Holes实际上是一个设置黑色补丁数的整数,那么您需要采用不同的方法:首先收集黑色补丁。最好为此引入全球holes

globals [holes]

to setup
  create-holes  ;; e.g., ask n-of num-Holes patches [set pcolor black]
  set holes patches with [pcolor = black]
end setup

to set-zombie-heading  ;; zombie proc
  if any? holes in-radius 5 [
    set heading (towards min-one-of holes [distance myself]) + 180
    set heading (heading + random 20 - 10)
  ]
end

答案 1 :(得分:2)

 if any? Patches in-radius 5 with[pcolor = black] [ stuff]
相关问题