在NetLogo中的列表中存储代理坐标
我试图创建一个简单的模拟代理随机移动,但避免某些障碍。我想让他们存储他们去过的地方的坐标,这样他们就不会再去那里了。这是我到目前为止所做的工作的一部分:在NetLogo中的列表中存储代理坐标,netlogo,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
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
然而,它一直给我一个“设置预期2个输入”错误。有人能帮我一下吗?看起来您错误地将
xy\u list
用作变量和海龟变量
我不认为有必要使用xy_列表过程-将其作为一个turtle变量。确保xy_列表在turtles自己的列表中:
turtles拥有[xy_列表]
创建海龟时,将其初始化为空列表。例如:
crt 1[设置xy\U列表[]]
当海龟移动时,您可以将其当前位置添加为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