如何在六角网格上移动邻居之间的海龟?

时间:2014-05-03 13:40:55

标签: netlogo

我想问一下如何将海龟移到邻居家。 (房子是六角形的细胞) 我试图做到但是给我一个错误。

;;;;;;;;;;;;制作房屋或六角形单元

 to setup-cells
 set-default-shape cells "hex"
 ask patches
 [ sprout-cells 1
 [ set color grey
  set size 1.2
  ;; shift even columns down
  if pxcor mod 2 = 0
  [ set ycor ycor - 0.5 ] ] ]
  ask cells
  [ ifelse pxcor mod 2 = 0
  [ create-links-with cells-on patches at-points [[0 1] [1 0] [1 -1]] ]
  [ create-links-with cells-on patches at-points [[0 1] [1 1] [1 0]] ] ]
  ask links [ hide-link ]
  end

;;;;;我把乌龟加到他们的房子里

to setup-population
ask patches [
 sprout 2 
    if pxcor mod 2 = 0
    [ set ycor ycor - 0.5 ]]
end 

我的问题是如何将这只乌龟移动到链接邻居

我试图这样做

to move 
 ask turtles[
   if ( random-float 1) < 0.03  [
 move-to one-of link-neighbors
fd 1 ]]
 end

但这总是给我一个错误

move-to expected input to be agent but got nobody instead

1 个答案:

答案 0 :(得分:1)

好问题。太糟糕了,Hex Cells Example(您似乎正在使用的代码示例)中没有涉及到这一点。或者我们应该有一个单独的Hex Cells with Turtles示例。

首先,你应该为住在房子里的海龟做一个单独的品种,所以你可以将它们与细胞龟分开。假设你称他们为人:

breed [people person]

然后您应该将sprout 2更改为sprout-people 2

至于实现移动,您尝试的代码不起作用,因为人们没有链接邻居。它是具有链接邻居的单元格。

所以而不是:

move-to one-of link-neighbors

你必须写:

move-to [one-of link-neighbors] of one-of cells-here

如果你希望人们面对运动方向,那就是:

let target [one-of link-neighbors] of one-of cells-here
face target
move-to target