为什么邻居块不以 NetLogo 中的海龟位置为中心?另外当在邻居处设置 "targets" 时为什么不往复运动?

Why aren't neighbor patches centered at turtle location in NetLogo? Also when setting "targets" when at neighbors why is it not reciprocate?

使用 Netlogo:我想要的是海龟根据它们的位置(然后根据它们的大小)吃其他海龟。我试过这段代码:

breed [cods cod]

cods-own [energy target]

to setup
  clear-all
  setup-patches
  setup-turtles
  reset-ticks
end

to setup-patches
  ask patches [set pcolor grey]
end

to setup-turtles
  create-cods number [
    set color blue
    setxy random-xcor random-ycor
    set shape "fish"
    set energy 100
    if random 100 < 80 [ set size  12]
    if random 100 < 75 [set size  11]
    if random  100 < 70 [set size  10]
    if random  100 < 65 [set size  9]
    if random  100 < 60 [set size  8]
    if random  100 < 55 [set size  7]
    if random  100 < 50 [set size  6]
    if random  100 < 45 [set size  5]
    if random  100 < 35 [set size 4]
    if random  100 < 30 [set size  3]
    if random  100 < 25 [set size  2]
    if random  100 < 20 [set size  1]
  ]
end

to go
if not any? cods [stop]
ask turtles [wander
    wiggle
    move
    eat
  check-if-dead
  ]
  ask cods [set size size + growth-rate
  set energy energy - movement-cost]
tick
  my-update-plots
end

to wander
  ask cods [
    wiggle
    move
  ]
  ;; sheep procedure, the sheep moves which costs it energy

end

;; sheep procedure, the sheep changes its heading
to wiggle
;; turn right then left, so the average direction is straight ahead
right random 90
left random 90
end

to move
forward 1
end

;; sheep procedure, if my energy is low, I die
to check-if-dead
if energy < 0 [
die
]
end

to eat
  if any? turtles-on neighbors[
    ask neighbors [set pcolor green]
    set target one-of turtles-on neighbors ;with [ size <= [size] of myself - 1 ]
    create-link-with target [set color red]
    ask target [ set color red]
  ]
end

我设置了一个目标并只设置了红色,这样我就可以检查发生了什么,但他们应该互相吃掉。问题是,当他们设定目标时,如果它基于“邻居”等补丁距离,我期望鉴于它们是互惠的邻居,两只海龟都会设置为红色,但这就是我得到的:

Only one is target, turtle not centered in neighbors

这意味着两个问题:

我认为问题在于鳕鱼的移动和进食发生在 go 过程中的同一个 ask 块中。请记住,在 ask 中,海龟被要求以随机顺序执行 ask 中的所有命令。因此,一条鳕鱼会在其附近找到另一条鳕鱼,为它创建一个 link 并将其变为红色。但是当ask走到那条红鳕鱼身边的时候,它已经因为自己的游荡、摆动和移动而移动了,所以它不再是邻居了。事实上,两条鳕鱼都移动了。当每个 cod 执行 go 过程中的 ask 时,它会依次要求所有 cod 在 wander 过程中摆动和移动。这就是为什么你发现原来的邻居鳕鱼都搬出了附近。如果你把eatgo过程中的ask中取出来,把它移到一个单独的ask中,在所有移动完成后执行,你会发现你得到你寻求的互惠。

有两件事需要考虑。首先,你想让每只鳕鱼都让所有的鳕鱼四处游荡,还是让它们自己四处游荡?其次,因为你所有的海龟(至少到目前为止)都是鳕鱼,所以在整个过程中使用 cod 而不是 turtle 可能更清楚。