这是一种方法:
您可以更改每种动物的中心补丁,并且可以设置您希望它们的领土重叠多少。
breed [animals animal]
animals-own [territory]
to setup
clear-all
create-animals number-of-animals / 2
[
set color red
set territory pathces-in-territory patch 10 10
move-to one-of territory
]
create-animals number-of-animals / 2
[
set color blue
set territory pathces-in-territory patch 15 15
move-to one-of territory
]
end
to-report pathces-in-territory [Center ]
let ptr []
ask Center [set ptr patches in-radius 5]
report ptr
end
你也可以这样做:
breed [animals animal]
animals-own [territory]
to setup
clear-all
create-animals number-of-animals / 2
[
set color red
set territory pathces-in-territory patch 10 10 5
move-to one-of territory
]
create-animals number-of-animals / 2
[
set color blue
set territory pathces-in-territory patch 15 15 10
move-to one-of territory
]
end
to-report pathces-in-territory [Center rd]
let ptr []
ask Center [set ptr patches in-radius rd]
report ptr
end
因为我喜欢示例;)这是另一个可以更改每个区域的 pcolor 的示例:
to-report pathces-in-territory [Center rd c]
let ptr []
ask Center [set ptr patches in-radius rd
ask patches in-radius rd [set pcolor c]
]
report ptr
end
你可以这样调用函数:set territory pathces-in-territory patch 10 6 15 blue
*更新
我应该稍后用 netlogo 检查它
create-animals number-of-animals
[
set color blue
move-to one-of patches with [not any? animals-here]
set territory patches in-radius 5
]
如果您希望为每只动物定义领土,您可以检查半径范围内是否没有海龟,例如 5,然后将领土设置为海龟周围的补丁
create-animals number-of-animals / 2
[
move-to one-of patches with [not any? animals in-radius 5]
set territory pathces-in-territory patch-here 2
let h who
ask territory [set pcolor h + 10 ] ; just for visual clarification
move-to one-of territory
]