Netlogo编码帮助-将海龟分成几个阵营,跟随上面的阵营,避免下面的阵营

Netlogo编码帮助-将海龟分成几个阵营,跟随上面的阵营,避免下面的阵营,netlogo,Netlogo,我是netlogo的新手,一直在将一个派系模型和遵循/避免模型中的代码组合在一起 我把我的乌龟分成了不同的阵营(显示为不同的颜色),我试图让它们跟随上面的阵营,避免下面的阵营。如果有人能看一看我的代码,那就太棒了,我认为这是行不通的,因为我试图用“品种”来区分谁是海龟在它们上面/下面判断的人,这需要对所有海龟都有所不同。我已经把我认为不允许它工作的地方用粗体表示 breed [ above ] breed [ below ] turtles-own [ faction ] to setup

我是netlogo的新手,一直在将一个派系模型和遵循/避免模型中的代码组合在一起

我把我的乌龟分成了不同的阵营(显示为不同的颜色),我试图让它们跟随上面的阵营,避免下面的阵营。如果有人能看一看我的代码,那就太棒了,我认为这是行不通的,因为我试图用“品种”来区分谁是海龟在它们上面/下面判断的人,这需要对所有海龟都有所不同。我已经把我认为不允许它工作的地方用粗体表示

breed [ above ]
breed [ below ]

turtles-own
[ faction ]

to setup
  clear-all
  ask patches [ set pcolor white ]
  set-patch-size 10
  resize-world min-pxcor max-pxcor min-pycor max-pycor 
  ask patch 0 0
   [ ask patches in-radius ( max-pxcor * .9) with [  random-float 100 < density ]
     [ sprout 1
       [ 
         set shape "circle"
         set faction random factions
         set color faction-color
         set size 1.1
         judge
       ]  ]   ]
   reset-ticks
end

to go
  ask turtles [ avoid ]   
  ask turtles
  [ fd 0.1
    if any? above in-radius 360; vision in patches and degrees
    [ set heading (towards min-one-of above [distance myself]) ] ]; adjusts heading to point towards   

 ask turtles
  [ fd 0.1
    if any? below in-radius 360; vision in patches and degrees
    [ set heading (towards min-one-of below [distance myself]) + 180 ] ] ; adjusts heading to point away from wanderer

  tick
end

to judge

  if turtle color = faction-color + 30 
  [ set breed above ]

  if turtle color = faction-color 
  [ set breed same ]

  if turtle color = faction-color - 30 
  [ set breed below ]

end

;; EXTRAS

to avoid
      ifelse not any? other turtles-on patch-ahead 1
      [ fd 0.1 ]
      [ rt random 360 ]
end

to-report faction-color
   report red + faction * 30
end
品种[如上]
繁殖[下]
乌龟自己的
[派系]
设置
清除所有
询问补丁[设置pcolor白色]
设置补丁大小为10
调整世界最小pxcor最大pxcor最小pycor最大pycor
询问修补程序0
[使用[random float 100
如果有人能给我指出正确的方向那就太好了。
再次感谢。

离你不远了。您已经正确地确定您对品种的使用是不适当的。“高于”或“低于”的属性是相对于提问的海龟而言的,而不是海龟本身的属性。可能有更好的方法来实现这一点,但只需对代码进行最小的更改,就可以执行以下操作:

to go
  ask turtles [ avoid ]    
  ask turtles [
    fd 0.1
    let above turtles with [ color = [faction-color] of myself + 30 ]
    if any? above in-radius 360; vision in patches and degrees
      [ set heading (towards min-one-of above [distance myself]) ] ; adjusts heading to point towards   
  ]
  ask turtles [
    fd 0.1
    let below turtles with [ color = [faction-color] of myself - 30 ]
    if any? below in-radius 360; vision in patches and degrees
      [ set heading (towards min-one-of below [distance myself]) + 180 ] ; adjusts heading to point away from wanderer
  ]
  tick
end

(然后,您可以完全删除您的
判断程序和
程序。)

我已将您的代码重新格式化为代码,但在此过程中丢失了粗体部分。无论如何,通常最好用注释标记您希望引起注意的代码部分,而不是使用粗体、斜体等格式。