我正在尝试选择连续patch-set
边缘的补丁,但我很难这样做。补丁集代表动物的领土。该地区的所有补丁都触及该地区的另一个补丁。我以为我可以选择领土neighbors4
的{{1}},然后让那些邻居依次选择属于该领土的邻居。这样理论上就可以选择领土的边缘。它运行但似乎没有选择正确的补丁。以下是我正在使用的代码段:
patch-set
答案 0 :(得分:3)
如果我理解你的情况,那么在领土外有邻居的任何领土都是边缘。而“境外”意味着没有同一所有者。在NetLogo中表达这一点的一种方法是:
patches-own [ owner-animal ]
to-report edge-patches [ territory ]
report territory with [
any? neighbors with [
owner-animal != [ owner-animal ] of myself
]
]
end
这是一个有趣的小演示,看看它在行动:
to setup
ca
ask n-of (2 + random 8) patches [
sprout 1 [
let territory patches in-radius (2 + random 8)
ask territory [
set owner-animal myself
set pcolor [ color ] of myself - 2
]
]
]
ask turtles [
let territory patches with [ owner-animal = myself ]
ask edge-patches territory [
set pcolor [ color ] of myself + 2
]
]
end