我刚接触过网络徽标。我正试着让红海龟向高楼移动。补丁。黄海龟不动。是我干的!但是我也想要求红海龟们不要再看到上面有黄、红海龟的地方,然后搬到高楼的邻居那里去。在我的代码中,我要求他们在被占用的补丁旁边停下来,因为我做不到。我也想避免让2只海龟在同一片土地上的任何时候。有人能帮我吗?
patches-own [conc]
to set-up
clear-all
ask patch random-pxcor random-pycor [
set conc 200
set pcolor scale-color red conc 0 1]
crt 5 [setxy random-xcor random-ycor set shape "circle" set color red]
crt 20 [setxy random-xcor random-ycor set shape "circle" set color yellow]
reset-ticks
end
to go
diffuse conc 0.1
ask patches [set pcolor scale-color red conc 0 1]
ask turtles with [color = red]
[ifelse not any? turtles-on neighbors
[if [conc] of max-one-of neighbors [conc] > conc [
face max-one-of neighbors4 [conc]
move-to max-one-of neighbors4 [conc]]]
[stop]
]
tick
end发布于 2013-11-18 13:22:45
如果您使用let来避免重复,我认为您的代码会读得更好一些,如下所示:
let target max-one-of neighbors [conc]
if [conc] of target > conc [
face target
move-to target
]有关强制执行“每个补丁一只海龟”规则的一些不同方法,请参阅NetLogo模型库的代码示例部分中的“每个补丁一海龟”示例模型。
我认为ifelse not any? turtles-on neighbors是你试图让海龟避免被占用的补丁。但是,正如你所写的,它有一个更强的效果-它使它使任何一个相邻的占用补丁的海龟不会移动在任何。
我想你的意思可能更像:
ask turtles with [color = red] [
let targets neighbors with [not any? turtles-here]
let target max-one-of targets [conc]
if target != nobody and [conc] of target > conc [
face target
move-to target
]
]希望这能有所帮助。
https://stackoverflow.com/questions/20032031
复制相似问题