我正在模拟有界天使内的随机行走,并且我想在模型中计算2D乌龟的mean squared displacement。乌龟都从中心开始。我不确定乌龟到达边界后如何更新其xy坐标。我要求海龟在撞到墙壁时反弹,并保存新的xcor和ycor。这是我的代码:
to go
ask turtles
[; head in a random direction in range (-theta, +theta)
ifelse theta = 0
[set heading heading + 0 ]
; choose a normally distributed random angel in range (-theta, +theta)
[set heading heading + random-normal 0 (theta)]
fd step-size
set xc xc + (step-size * dx)
set yc yc + (step-size * dy)
; if your next patch is blocked:
ifelse not can-move? 1
[ set heading heading + 180
fd 1 ]
;otherwise:
[rt random-float random-normal 0 (theta)]
set xcor xc
set ycor yc
set dist sqrt (xc * xc + yc * yc)]
]
我收到错误提示: “不能将海龟移出世界边缘。 乌龟423运行SET时出错 通过过程GO调用 由Button'go'调用。“有什么想法吗?
答案 0 :(得分:2)
您禁用了网格换行功能,代理的xcor / ycor超过了max-pxcor / min-pxcor和max-pycor / min-pycor