如何将乌龟移动到尽可能接近某个补丁的位置?

时间:2016-06-14 11:44:04

标签: netlogo

我有一个蓝色的补丁,并希望将乌龟移动到最近的空补丁。我能想到这样做的唯一方法是在循环中使用in-radius,每次将半径大小增加一,但是有更好的方法吗?

1 个答案:

答案 0 :(得分:1)

globals [bluey]

to setup
  ca
  ask one-of patches [set pcolor blue set bluey self]
  ask n-of 250 patches [sprout 1]
end

to-report nearest-empty [#patch]
  report min-one-of 
         [other (patches with [not any? turtles-here])] of #patch
         [distance #patch]
end

to test
  setup
  ;the following fails if all patches occupied
  ;(can add a test for nobody)
  ask nearest-empty bluey [set pcolor red]
end