我希望我的代码可以根据滑块中给出的海龟数量进行更多压缩,我希望将其重点放在原点上 . 如果这是我的代码
to solid
set color blue
set xcor random sqrt number-of-particles - number-of-particles / 2
set ycor random sqrt number-of-particles - number-of-particles / 2
ifelse any? patches with [pcolor = black and count turtles-here = 0]
[move-to one-of patches with [pcolor = black and count turtles-here = 0]]
[die]
end
我将如何包括它以便乌龟移动到最接近原点的空补丁?到目前为止我有
if number-of-particles < volume * volume
[move-to one-of patches with [
1 回答
假设"origin",你的意思是
patch 0 0
,这是一种方法:这两个关键部分是min-one-of和distance .
还要注意我已经用
not any? turtles-here
替换了count turtles-here = 0
,它基本上做同样的事情,但更具可读性 . 我还在free-patches
变量中存储了patches with [pcolor = black and not any? turtles-here]
,因此您不必重复自己并测试该条件的所有补丁两次 .