让一只乌龟跟随其邻居的特定乌龟

Have a turtle follow a specific one from its neighbors

我有 0 < AD < 1 和 0 < 意见 < 1 的海龟。每只海龟都链接(未定向)给定数量的其他海龟。我希望 AD 低的海龟 (< 0.3) 采纳另一只 AD 高 (> 0.7) 的海龟的意见,这些海龟属于他们的链接邻域。我想出的代码采用了扩展网络中所有具有高 AD 的海龟的所有意见。关于如何使它采纳附近某个人的意见的任何想法,如果有一个(可能没有) ?

这与之前的问题有关 ()

to opinion-formation
ask turtles [ 
let leaders turtles with [AD > 0.7]
if (AD < 0.3) and (link-neighbor? one-of leaders) [set opinion1 [opinion] of turtles with [link-neighbor? one-of leaders ]]
]
end

我试过的另一件事,这里的问题是我的乌龟从不采纳任何人的意见...

to opinion-formation
ask turtles [
let leaders turtles with [AD > 0.7]
if (count leaders with [member? self link-neighbors] > 0) and AD < 0.3 [
set opinion1 [opinion] of one-of leaders with [member? self link-neighbors]
]
]
end

您可能需要为此使用 nw 扩展,因为它允许您使用 nw:turtles-in-radius X 原语来 return 连接距离内的海龟。举一个非常简单的例子,看看这段代码:

extensions [ nw ]

turtles-own [ AD ]

to setup
  ca
  crt 10
  ask turtles [
    set AD random-float 1
    set color scale-color blue AD 0 1
    setxy random 20 - 10 random 20 - 10
    create-link-with one-of other turtles
  ]
  reset-ticks
end

to check-leadership
  ask turtles [
    let my-nearby-turtles nw:turtles-in-radius 2
    let my-nearby-leader one-of my-nearby-turtles with [ AD > 0.7 ]
    if my-nearby-leader != nobody [
      let new-AD [AD] of my-nearby-leader
      show word "I have a leader, my new AD is " new-AD
      set AD new-AD      
      set color scale-color blue AD 0 1 
    ]
  ]
end