NetLogo从修补程序变量查询海龟变量

NetLogo从修补程序变量查询海龟变量,netlogo,Netlogo,我正在尝试选择所有者的状态小于我自己的的邻居补丁。如果存在此类修补程序,则我自己将其范围扩展到这些修补程序,并成为所有者。但是我很难让NetLogo识别相邻补丁的所有者的状态。我可以选择拥有所有者的邻居,然后打印这些所有者的状态,但仅此而已。任何帮助都将不胜感激。代码如下 breed [animals animal] animals-own [ orig territory food status] patches-own [ owner hsi] to setup clea

我正在尝试选择
所有者的
状态小于
我自己的
的邻居补丁。如果存在此类修补程序,则
我自己
将其范围扩展到这些修补程序,并成为
所有者
。但是我很难让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
繁殖[动物]
动物拥有[原领地食物状态]
个人[所有者hsi]
设置
清除所有
询问补丁
[ 
无人拥有
将hsi随机设置为5
设置pcolor刻度颜色(黑色)hsi 1 4
] 
let$colors[红粉黄蓝橙棕灰紫天青]
询问n-10个补丁
[ 
发芽动物1
[ 
在这里设置原始补丁
集合区域补丁集合原点
将状态设置为随机4
设置颜色项$colors
设置颜色
设置所有者自身
放下笔
] 
] 
重置滴答声
结束
外带
如果有的话?动物[食物>=150][停止]
如果滴答声=50[停止]
询问动物[展开]
打上钩
结束
扩大
让邻里没有补丁
让我们不要补补丁
如果食物<150
[ 
询问领土
[
如果有?与[所有者=无人]的邻居
[
设置Neightrline(修补程序设置[owner=nobody]的Neightrline Neights);这可以正常工作。
]
如果有?与[所有者!=无人]的邻居
[
set pot comp(修补程序设置pot comp邻居,所有者的[[status]小于我自己的[status]);这不起作用。我做错了什么?
]
]
设目标为3条邻域线的最大n值[hsi]
设置区域(补丁设置区域目标);将区域增加到3个补丁,没有所有者和最高HSI
询问领土
[ 
我自己定了主人
设置我自己的颜色
]
设定领土的食物总量[hsi]
]
结束
在这段代码中:

if any? neighbors with [owner != nobody]
[
  set pot-comp (patch-set pot-comp neighbors with
    [[status] of owner < [status] of myself]) 
]
但是你会得到一个补丁在没有指定哪个海龟的情况下无法访问海龟变量。这是因为
with
使你在询问者层次结构中更深一层,所以
我自己
现在指的是补丁,而不是像你可能希望的那样指动物。通过使用临时变量(例如,
让当前动物自身
位于
展开过程的顶部),您始终可以绕过此类问题。在您的情况下,我会直接将状态存储在变量中。稍微重组后,您当前的
ask territory
块可能会变成:

let my-status status ; store this while `self` is the animal
ask territory
[
  set neighborline (patch-set neighborline neighbors with [owner = nobody])
  set pot-comp (patch-set pot-comp neighbors with
    [owner != nobody and [status] of owner < my-status])
]
让我的状态;当“self”是动物时,储存这个
询问领土
[
设置邻居线(修补程序设置具有[owner=nobody]的邻居线)
设置电位计补偿(修补程序设置电位计补偿邻居)
[所有者!=无人和所有者的[状态]<我的状态])
]
注意我去掉了
(如果有的话)?带有[…]的邻居
检查。您并不真正需要它们:如果没有适合您的条件的修补程序,您只需将空修补程序集添加到现有修补程序集,这并不重要。

在这段代码中:

if any? neighbors with [owner != nobody]
[
  set pot-comp (patch-set pot-comp neighbors with
    [[status] of owner < [status] of myself]) 
]
但是你会得到一个补丁在没有指定哪个海龟的情况下无法访问海龟变量。这是因为
with
使你在询问者层次结构中更深一层,所以
我自己
现在指的是补丁,而不是像你可能希望的那样指动物。通过使用临时变量(例如,
让当前动物自身
位于
展开过程的顶部),您始终可以绕过此类问题。在您的情况下,我会直接将状态存储在变量中。稍微重组后,您当前的
ask territory
块可能会变成:

let my-status status ; store this while `self` is the animal
ask territory
[
  set neighborline (patch-set neighborline neighbors with [owner = nobody])
  set pot-comp (patch-set pot-comp neighbors with
    [owner != nobody and [status] of owner < my-status])
]
让我的状态;当“self”是动物时,储存这个
询问领土
[
设置邻居线(修补程序设置具有[owner=nobody]的邻居线)
设置电位计补偿(修补程序设置电位计补偿邻居)
[所有者!=无人和所有者的[状态]<我的状态])
]

注意我去掉了
(如果有的话)?带有[…]的邻居
检查。您并不真正需要它们:如果没有适合您的条件的修补程序,您只需将空的修补程序集添加到现有的修补程序集,这并不重要。

谢谢Nicolas!我在这件事上纠缠太久了。现在我知道我自己所指的是错误的级别。谢谢尼古拉斯!我在这件事上纠缠太久了。现在我知道
我自己
指的是错误的级别。