netlogo 中每只乌龟的具体位置

specific position for each turtle in netlogo

我在netlogo的设置过程中有如下代码

  set-default-shape Mappers "target"
  create-mappers MappersCounterSlider
  [
    set color red
    set size 1.5  ;; easier to see
    set label-color blue - 2
    set xcor 10
    set ycor random 11

  ]

我需要为我创建的每只乌龟将随机数 11 更改为特定值,例如,如果我有 5 只乌龟,我想在不同的 5 个固定位置放置 5 只乌龟。

如果您需要每只乌龟的特定 y 坐标,恐怕您将不得不自己设置它们。

如果您不关心哪只乌龟位于哪个 y 坐标,您可以有一个可能的 y 坐标列表,然后每只乌龟将从中移除以确定它们的 y 坐标

例如,如果您需要海龟从 y 坐标 1、2、5、8 和 9 开始,请创建一个列表:

let y-coordinates (list 1 2 5 8 9)

然后当您创建海龟时,将它们的 y 坐标设置为从列表中删除的随机元素。

let remove-index random length y-coordinates
set ycor item remove-index y-coordinates
set y-coordinates remove-item remove-index y-coordinates 

这样,如果您想添加更多固定的 y 坐标,只需将其添加到列表即可。

您还可以在创建过程中通过递增全局变量来指定位置。像下面这样:

globals [posn]

to setup
  set posn -10
  create-turtles 5
  [
    set color red
    set size 1.5  ;; easier to see
    set label-color blue - 2
    set xcor 10
    set posn posn + 3
    set ycor posn

  ]
end