将海龟移动到NetLogo中其他代理的特定坐标

时间:2014-05-14 16:39:58

标签: coordinates netlogo

我有个人(海龟),我有家庭(固定xy的乌龟) 我在家庭中存储了一个变量地址。我有一个家庭附属于个人。这些家庭的人数相同。 我如何将个人安置或移动到相应的家庭? 我试过像:

ask individuals
   [ if family = [family-place] of household
      [
        move-to [address] of household 
      ]                        
   ]

3 个答案:

答案 0 :(得分:1)

move-to household应该这样做。

答案 1 :(得分:1)

因为周一早上很慢,所以我会这样做。 我假设 familiy-number 是移动海龟和无柄海龟中常见数字的名称。我会使用创建一个只在该过程中起作用的局部变量。 (请参阅 go-home 程序)

breed [walkers walker] 
breed [houses house]

houses-own [family-number] 
walkers-own [family-number] 


to setup 
  clear-all 
  set-default-shape houses "house"
  create-houses 10 [
    setxy random-xcor random-ycor
    set family-number random 10000
  ]  
  reset-ticks
end 

to leave-home 
  ask houses [
    hatch-walkers 1 [
      set family-number [family-number] of myself 
      set color [color] of myself 
      set heading random 360 
      fd 1 
    ]
  ]
end 

to go
  ask walkers [
    rt random 120 
    lt random 120   
    fd 1
  ]
  tick 
end 

to go-home 
  ask walkers [
    let family-place one-of houses with [family-number = [family-number] of myself]
    move-to family-place  
    fd 1 ;; walker will step away one step so we can see him. 
  ]
end 

只需将其复制到NetLogo中,为每个程序制作一个按钮并播放。如果按顺序

,效果最佳
setup  
leave-home
go  
go-home

希望这有帮助!

答案 2 :(得分:0)

我无法理解你的问题,因此我不得不猜测你想要什么,但在你对布莱恩的回答评论的帮助下,也许我已经猜到了正确?

ask individuals [
  move-to one-of households with [address = [family-place] of myself]
]

如果由于myself这看起来很混乱,你也可以把它写成:

ask individuals [
  let f family-place
  move-to one-of households with [address = f]
]