我正在尝试创建一个模型,其中海龟随机行走(但有向前移动的趋势),直到它们落在代表诱饵物体的黄色斑块上。
当一只海龟落在其中一个黄色斑点上时,我希望它停在该斑点上并在那里停留 15 个刻度,同时“调查”诱饵。
15 个刻度过后,我希望海龟继续像往常一样移动,直到遇到另一个黄色斑块。
我试图在 netlogo 建模共享中修改此停放卡模型的部分内容,但无法真正理解它(我是 netlogo 的新手) http://modelingcommons.org/browse/one_model/3205#model_tabs_browse_procedures
我还尝试实现一个倒计时器,如该线程 How can one create a countdown timer in NetLogo?中所述。
但是,当我尝试运行模拟时,我收到运行时错误“只有观察者可以询问所有海龟的集合”。谁能告诉我哪里错了?大概好几个地方吧!谢谢。
这是导致运行时错误的代码:
turtles-own [count-down]
to setup
clear-all
ask patches with [count neighbors != 8]
[set pcolor blue]
create-turtles 20
ask turtles
[setxy random-xcor random-ycor
pen-down]
ask n-of 20 patches
[ set pcolor yellow ]
reset-ticks
end
to go
move-turtles
tick
if ticks >= 720 [stop]
end
to move-turtles
ask turtles
[ ifelse pcolor != yellow
[continue]
[stay]
]
end
to continue
ask turtles
[rt -90 + random 181]
ask turtles
[ifelse [pcolor] of patch-ahead 1 = blue [ lt random-float 360 ]
[fd 1]
]
end
to stay
ask turtles
[
setup-timer
decrement-timer
if timer-expired? [continue]
]
end
to setup-timer
set count-down 15
end
to decrement-timer
set count-down count-down - 1
end
to-report timer-expired?
report ( count-down <= 0 )
end
Run Code Online (Sandbox Code Playgroud)
这只是一个例子,他们应该在黄色区域停留多少个蜱虫?我假设有 15 个刻度,我也要求海龟在标签上打印它们的刻度编号,如果它运行得太快,您可能会错过它们的停留时间,因此请调整模型的运行速度,以查看它们何时停留和何时移动。您可以采用不同的方法来继续,在这一方法中,他们只是向前移动 1 个补丁。
turtles-own [count-down]
to setup
clear-all
ask patches with [count neighbors != 8]
[set pcolor blue]
create-turtles 20
ask turtles
[setxy random-xcor random-ycor
pen-down
set count-down 15
]
ask n-of 20 patches
[ set pcolor yellow ]
reset-ticks
end
to go
move-turtles
tick
if ticks >= 720 [stop]
end
to move-turtles
ask turtles
[ ifelse pcolor != yellow
[continue]
[stay]
]
end
To continue
rt random 10
fd 1
end
to stay
set count-down count-down - 1 ;decrement-timer
set label count-down
if count-down = 0
[
Continue
set label ""
reset-count-down
]
end
to reset-count-down
set count-down 15
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11143 次 |
| 最近记录: |