NETLogo将海龟向中间的补丁停止移动 我希望我的海龟向一个随机的方向移动,但是在距离中间停下来,然后选择另一个随机的补丁,然后在中间停止。
我在开发代码时遇到了很多问题。我希望这有帮助NETLogo将海龟向中间的补丁停止移动 我希望我的海龟向一个随机的方向移动,但是在距离中间停下来,然后选择另一个随机的补丁,然后在中间停止。,netlogo,move,Netlogo,Move,我在开发代码时遇到了很多问题。我希望这有帮助 breed [destinations destination] breed [people person] globals [start dist_so_far on-going] to setup clear-all create-people 1 [set shape "person" set color black] create-destinations 5 ask destinations[set shape "flag
breed [destinations destination]
breed [people person]
globals [start dist_so_far on-going]
to setup
clear-all
create-people 1 [set shape "person" set color black]
create-destinations 5
ask destinations[set shape "flag" setxy random-xcor random-ycor]
ask patches [set pcolor white]
end
to go
foreach sort-on [who] destinations [?1 ->
set on-going true
while [on-going][
ask ?1 [watch-me hatch 1 [set hidden? true set start self]]
ifelse dist_so_far <= real_dist start
[ask one-of people [face ?1 fd 0.5 set dist_so_far dist_so_far + 0.5]]
[ask ?1 [die] set on-going false]
]
]
end
to-report real_dist [x]
let dist_x abs([xcor] of x - [xcor] of one-of people) / 2
let dist_y abs([xcor] of x - [xcor] of one-of people) / 2
report sqrt(dist_x ^ 2 + dist_y ^ 2)
end
品种[目的地]
繁殖[人]
globals[目前正在进行的起始距离]
设置
清除所有
创建人物1[设置形状“人物”设置黑色]
创建目的地5
询问目的地[设置形状“标志”setxy random xcor random ycor]
询问补丁[设置pcolor白色]
结束
外带
foreach对[谁]目的地进行排序[?1->
不断地实现
在[进行中][
询问?1[观察我舱口1[设置隐藏?真正设置开始自我]]
如果距离不远,我只知道移动到随机补丁:设置清除所有创建海龟1[设置颜色白色setxy random xcor random ycor]结束移动到其中一个补丁结束查看“移动到目标示例”在模型库中-应该可以开始了。您好,欢迎使用Stack Overflow!您可以在发布问题后编辑问题。这是一种比将问题添加到注释中更好的方法-很难在注释中读取代码,因为它最终都被压缩到一行中。