Netlogo 我的乌龟标签上可能有变量吗
我希望我的变量继承海龟的标签 我在为他们定路线,希望他们记住上次去的地方 所以他们会继续到链条的下一个位置Netlogo 我的乌龟标签上可能有变量吗,netlogo,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]] 我不能在这里使用我的实际代码,但希望你能理解要点
ifelse last_place = home
[set place min-one-of (turtles with [label = "mall"])[distancemyself]]
[set place min-one-of (turtles with [label = "home"])[distancemyself]]
我不能在这里使用我的实际代码,但希望你能理解要点
如果
我想补充一点
设置最后一个位置
位置标签
我想要last\u place
获得位置标签
我知道如果我在同一条路线上有两次相同的位置,它可以创建循环,但我想创建一个列表来防止它们,但现在我需要一种where标志,它可以让我的海龟们一直走到尽头。如果看不到更多的代码,很难说-很难知道海龟们在做什么。如果您的代码是敏感的,我建议您按照中的提示制作一个可复制的示例-这样可能更容易解决您的确切问题 作为替代,与其使用标签,不如让海龟将“位置”海龟或补丁存储在海龟变量中。使用此简单示例设置:
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
向civis询问[ifelse等待时间>0]
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