我試圖選擇owner
龜的status
小於myself
的鄰居補丁。如果存在這種補丁,則myself
將其領土擴展到這些補丁併成爲owner
。但我無法要求NetLogo確定相鄰修補程序owner
的status
。我可以用owner
選擇鄰居,然後打印這些所有者的status
,但就是這樣。任何幫助將非常感激。代碼如下。NetLogo從補丁變量查詢龜變量
breed [animals animal]
animals-own [ orig territory food status]
patches-own [ owner hsi]
to setup
clear-all
ask patches
[
set owner nobody
set hsi random 5
set pcolor scale-color (black) hsi 1 4
]
let $colors [red pink yellow blue orange brown gray violet sky lime]
ask n-of 10 patches
[
sprout-animals 1
[
set orig patch-here
set territory patch-set orig
set status random 4
set color item who $colors
set pcolor color
set owner self
pen-down
]
]
reset-ticks
end
to go
if all? animals [food >= 150] [ stop ]
if ticks = 50 [ stop ]
ask animals [ expand ]
tick
end
to expand
let neighborline no-patches
let pot-comp no-patches
if food < 150
[
ask territory
[
if any? neighbors with [owner = nobody]
[
set neighborline (patch-set neighborline neighbors with [owner = nobody]) ;this works fine.
]
if any? neighbors with [owner != nobody]
[
set pot-comp (patch-set pot-comp neighbors with [[status] of owner < [status] of myself]) ; this does not work. What am I doing wrong?
]
]
let target max-n-of 3 neighborline [hsi]
set territory (patch-set territory target) ; grow territory to 3 patches with no owners and highest HSI
ask territory
[
set owner myself
set pcolor [color] of myself
]
set food sum [hsi] of territory
]
end
謝謝Nicolas!我一直陷在這太久。現在我明白「我自己」是指錯誤的水平。 – user2359494