我的乌龟标签是否有可能变化

时间:2017-12-07 09:47:07

标签: netlogo

我希望我的变量继承我的海龟的标签。

我为他们制作路线,并希望他们记住他们去过的最后一个地方。

所以他们会继续到链中的下一个位置。

ifelse last_place = home 

[set place min-one-of (turtles with [label = "mall"])[distancemyself]]

[set place min-one-of (turtles with [label = "home"])[distancemyself]]

我不能在这里使用我的实际代码,但希望你得到要点

如果

place = one-of turtles with [label = "mallI]

我想添加

设置last_place地方标签

我希望last_place获得地点标签。

我知道它可以创建循环,如果我在相同的路线中有两次相同的地方但我想创建一个列表来防止它们但是现在我需要一种哪种标志会让我的乌龟一直走到尽头

1 个答案:

答案 0 :(得分:1)

很难说没有看到更多的代码 - 很难知道乌龟在做什么。如果您的代码是敏感的,我建议您按照MCVE guidelines中的提示制作可重现的示例 - 以这种方式解决您的确切问题可能更容易!

作为替代方案,不要使用标签,最好只让乌龟将“位置”乌龟或补丁存储在乌龟变量中。使用这个简单的示例设置:

breed [ walkers walker ]
breed [ locations location ]

walkers-own [ location-list ]

to setup
  ca
  create-walkers 10 [
    setxy random-pxcor random-pycor
    set location-list []
    pd
  ]
  create-locations 20 [
    set size 1.5
    set shape "house"
    setxy random-pxcor random-pycor
  ]
  reset-ticks
end

您可以让海龟将他们访问的地点存储在列表中并以这种方式引用它们。

to go
  ask walkers [

    ; Build an agrentset of locations that do not belong 
    ; to each turtle's 'location-list'
    let unvisited-locations locations with [ 
      not member? self [location-list] of myself
    ]

    ; Target the nearest unvisited location
    let target min-one-of unvisited-locations [ distance myself ]

    ; if the target exists, move towards it
    if target != nobody [
      face target
      ifelse distance target > 1 [
        fd 1 
      ] [ 
        move-to target
        set location-list lput target location-list
      ]
    ]

    ; if a turtle visits all locations, remove the
    ; first location visited from the 'location-list'
    ; so that it will follow the same pattern continuously
    if length location-list = count locations [
      set location-list but-first location-list
    ]
  ]
  tick
end