在 NetLogo 的列表中存储代理坐标

Storing agent coordinates in a list in NetLogo

我正在尝试创建一个代理随机移动但避开某些障碍物的简单模拟。我希望他们存储他们去过的地方的坐标,这样他们就不会再去那里了。这是我目前所拥有的一部分:

to move-agent

  let move random 3
  if (move = 0) []
  if (move = 1)[ left-turn ]
  if (move = 2)[ right-turn ]

  set xint int xcor  ;;here i'm storing the coordinates as integers
  set yint int ycor

  set xylist (xint) (yint)

  go-forward

end

to xy_list
  set xy_list []
  set xy_list fput 0 xy_list ;;populating new list with 0
end

但是,它一直给我一个 "SET expected 2 inputs" 错误。谁能帮我解决这个问题?

您似乎错误地使用了 xy_list 作为变量和 turtle 变量。

我认为不需要 xy_list 过程 - 将其保留为 turtle 变量。确保 xy_list 在 turtles-own 列表中:

turtles-own [xy_list]

创建海龟时将其初始化为空列表。例如:

crt 1 [set xy_list []]

当海龟移动时,您可以将它们的当前位置添加为 xcor、ycor 列表:

set xy_list fput (list int xcor int ycor) xy_list

然后您需要在移动到那里之前检查该坐标是否已经存在于列表中。

但是,由于您使用的是整数坐标,因此使用补丁集来跟踪海龟的历史会容易得多。你可以试试这个:

turtles-own [history]

to setup
  ca
  crt 3 [set history (patch-set patch-here) pd]
end

to go
  ask turtles [
    let candidates neighbors with [not member? self [history] of myself]
    ifelse any? candidates 
      [move-to one-of candidates stamp
       set history (patch-set history patch-here)]
      [die]   
  ]
end