netlogo - 随机 select 一个具有更高海拔的邻居补丁,有吗?命令

netlogo - Randomly select a neighbour patch that has a higher elevation, any? command

我的任务是 "randomly selecting a neighbour patch that has a higher elevation." 我的代码在下面找到。

我认为我需要使用 "any?" 命令来防止出现 'nobody' 问题。

to move-up
let myelevPatch [elevation] of patch-here
let higherpatches neighbors with [elevation > myelevPatch] 
move-to one-of higherpatches
end

我似乎无法解决这个问题,如果你能帮助我解决这个问题,我将不胜感激

除了 nobody 的情况外,您的代码似乎是正确的。任何?消耗代理集。具有 returns 个代理集的邻居。

to move-up
    let myelev [elevation] of patch-here
    let higherpatches neighbors with [elevation > myelev] 
    if any? higherpatches
    [move-to one-of higherpatches]
end

注意以下是等效的:

if count higherpatches > 0