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



我想问一下如何把乌龟转移到它们的邻居那里。(房子是十六进制的)我试着做了,但给了我一个错误。

;;;;;;;;;;;;; 使房屋或十六进制细胞

 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 

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

I tried to do this

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

问得好。这是太糟糕了,这是不包括在十六进制单元格示例(代码示例,你似乎是从工作)。或者我们应该有一个单独的十六进制单元格与海龟的例子。

首先,你应该为住在房子里的海龟做一个单独的品种,这样你就可以把它们和细胞龟分开来参考。假设你称他们为人:

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

最新更新