如何在接近目标时更改前进速度,NetLogo

huangapple go评论44阅读模式
英文:

How to change the forward speed when near the objetctive netlogo

问题

询问 Buteo-platypterus [ 面向 min-one-of patches with [pcolor = green ] [distance myself] 如果 distance patches with [pcolor = green] < 5 [fd 1] [fd 5 set energia energia - 5] ]

英文:

i have bird that can fly really long distances, so it has a foward of 5. However its not reaching its destination as flying in intervals of 5 makes it jump the mark. To solve it i tried this.

ask Buteo-platypterus[ face min-one-of patches with [pcolor = green ] [distance myself] ifelse distance patches with [pcolor = green] < 5 [fd 1][ fd 5 set energia energia - 5] ]

Distance expects an agent or patch but it's getting an agentset. How do i make the bird go slower when its near the destination?

答案1

得分: 2

ifelse distance patches with [pcolor = green][...]
这行代码是你的问题。你正在询问到所有绿色斑块的距离,而不是到最近的绿色斑块。

ifelse distance min-one-of patches with [pcolor = green] [distance myself] [...]
这应该解决问题。你还可以使用一个本地变量,以免一遍又一遍地重写相同的代码(这可能导致错误)。

   let destination min-one-of patches with [pcolor = green ] [distance myself] 
   face destination 
   ifelse distance destination < 5 [fd 1][ fd 5 set energia energia - 5] 
]```

<details>
<summary>英文:</summary>

`ifelse distance patches with [pcolor = green][...]`
This line of code is your problem. You are asking the distance to all green patches, an agentsent, instead of to the closest green patch. 

    

    ifelse distance min-one-of patches with [pcolor = green] [distance myself] [...]

This should solve the problem. You could also use a local variable to not have to rewrite the same code over and over again (which can lead to mistakes)

    ask Buteo-platypterus [ 
       let destination min-one-of patches with [pcolor = green ] [distance myself] 
       face destination 
       ifelse distance destination &lt; 5 [fd 1][ fd 5 set energia energia - 5] 
    ]



</details>



huangapple
  • 本文由 发表于 2023年2月24日 03:56:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75549727.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定