英文:
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 < 5 [fd 1][ fd 5 set energia energia - 5]
]
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论