我希望人类(乌龟)走到杂草(乌龟)处,然后在控制台中显示人类到达了杂草,然后什么也不做

问题描述 投票:0回答:1

我希望一个人走到杂草处,然后在控制台中显示它到达了杂草,然后停下来。每当我启动模型时,一个人走到一棵杂草处,并显示它到达了杂草处,但随后走到另一棵杂草处,一遍又一遍……一遍又一遍。

这是代码(人类应该从杂草中获取 1 种食物)

to action_human
   if food < 1 [
      ask one-of humans [ 
         let temp-weed one-of weeds
         face temp-weed
         while [distance temp-weed > 1] [
             ifelse distance temp-weed < 1 [ move-to temp-weed ] [ fd 1]
         ] 
         show "weed reached" 
         set food food + 1
      ]
   ]
end
netlogo
1个回答
1
投票

您的代码中的其他内容一定是错误的。我使用了与您完全相同的代码,它的行为符合预期的描述。我附上了完整的代码示例。

breed [humans human]
breed [weeds weed]

humans-own [food]

to setup
  ca
  create-humans 1 [
    setxy random-xcor random-ycor
    set food 0
  ]
  create-weeds 1 [
    setxy random-xcor random-ycor
  ]
  reset-ticks
end

to go
  ask humans [action_human]
  tick
end



to action_human
 if food < 1 [
    ask one-of humans [
     let temp-weed one-of weeds
     face temp-weed
     while [distance temp-weed > 1] 
     [
        ifelse distance temp-weed < 1 
        [
          move-to temp-weed] [
          fd 1
        ]
     ]
     show "weed reached" set food food + 1
    ]
  ]
end
© www.soinside.com 2019 - 2024. All rights reserved.