Netlogo:龟的明显不稳定行为
Netlogo: apparent erratic behavior of turtle
我有一个模型,其中创建了人和门。人类面向门 运行 然后退出。问题是有些人会因为某种原因停下来。即使只使用一个人,它有时会到达门口,有时则不会。我必须做什么才能让人们总是到达门口?这是model,这是代码:
globals [ID-door]
breed [door doors]
breed [human humans]
to setup
clear-all
set-default-shape door "star"
crt number [
setxy random-xcor random-ycor
set color cyan
set breed human]
new-door
reset-ticks
end
to new-door
ask one-of patches [sprout-door 1]
ask door [
set color yellow
set size 2
set ID-door who]
end
to go
if count human = 0 [stop]
ask human [
move-human
check-door]
tick
end
to move-human
face doors ID-door
ifelse any? human-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1]
end
to check-door
if any? door-on patch-here [die]
end
您的问题是patch-ahead 1
。无论乌龟面向什么方向,它看起来的距离都是 1。想象乌龟在左上角并朝右下角看。到角的距离 >1,乌龟正在触发 'stay here' 检查,并且会被卡住,直到它充分转身,以便在它前面有一个不同的补丁。
所以你需要让乌龟将自己排除在检查之外,这是 other
的工作。将 ifelse any? human-on patch-ahead 1
更改为 ifelse any? other human-on patch-ahead 1
。
我将移动人物程序更改为以下内容,现在模型可以运行了:
to move-human
ifelse patch-ahead 1 = nobody or any? other humans-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1
face door ID-door]
end
正如 JenB 所述,patch-ahead 1
是问题所在,因此:
a) 因为世界有水平和垂直限制(它不是包裹的 space),当达到这些限制时,行 patch-ahead 1 = nobody
检查是否没有补丁。
b) other humans-on patch-ahead 1
行排除了当前海龟,因为它可能被计算在内,因为 1
的距离可能仍在当前补丁内,如下图:
我有一个模型,其中创建了人和门。人类面向门 运行 然后退出。问题是有些人会因为某种原因停下来。即使只使用一个人,它有时会到达门口,有时则不会。我必须做什么才能让人们总是到达门口?这是model,这是代码:
globals [ID-door]
breed [door doors]
breed [human humans]
to setup
clear-all
set-default-shape door "star"
crt number [
setxy random-xcor random-ycor
set color cyan
set breed human]
new-door
reset-ticks
end
to new-door
ask one-of patches [sprout-door 1]
ask door [
set color yellow
set size 2
set ID-door who]
end
to go
if count human = 0 [stop]
ask human [
move-human
check-door]
tick
end
to move-human
face doors ID-door
ifelse any? human-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1]
end
to check-door
if any? door-on patch-here [die]
end
您的问题是patch-ahead 1
。无论乌龟面向什么方向,它看起来的距离都是 1。想象乌龟在左上角并朝右下角看。到角的距离 >1,乌龟正在触发 'stay here' 检查,并且会被卡住,直到它充分转身,以便在它前面有一个不同的补丁。
所以你需要让乌龟将自己排除在检查之外,这是 other
的工作。将 ifelse any? human-on patch-ahead 1
更改为 ifelse any? other human-on patch-ahead 1
。
我将移动人物程序更改为以下内容,现在模型可以运行了:
to move-human
ifelse patch-ahead 1 = nobody or any? other humans-on patch-ahead 1
[rt random 40 lt random 40]
[fd 1
face door ID-door]
end
正如 JenB 所述,patch-ahead 1
是问题所在,因此:
a) 因为世界有水平和垂直限制(它不是包裹的 space),当达到这些限制时,行 patch-ahead 1 = nobody
检查是否没有补丁。
b) other humans-on patch-ahead 1
行排除了当前海龟,因为它可能被计算在内,因为 1
的距离可能仍在当前补丁内,如下图: