【发布时间】:2022-10-13 00:52:50
【问题描述】:
我正在尝试模拟人们在 Netlogo 中登上公共巴士。 但是,我对编码的经验很少。我试图自己创建它,但遗憾的是我被卡住了。所以我希望你能帮助我。我将首先解释我想要编码的内容,然后我将展示我当前的代码。提前致谢!
因此,我们的想法是创建一个平台(白色斑块),让海龟(乘客)等待上车。我想给乘客一个人的形状,给公共汽车一个公共汽车的形状。 目前我确实有乘客在站台等候,但我无法让他们移动到公共汽车上。
除此之外,我不知道如何让公共汽车移动。所以它停在平台旁边,过了一段时间它应该离开。为此,从 1 只大乌龟中制造了一辆大巴士。然后当公共汽车到达时,乘客们去公共汽车上车,编码这个我想让海龟“死”。但是,看起来海龟并没有在我的代码中死去。你们知道我怎样才能让公共汽车到达、乌龟上车(死)和公共汽车离开吗?
我当前的代码:
turtles-own [target trip]
breed [bus a-bus]
to setup
clear-all
ask patches with [pxcor = -1 and pycor = -1][set pcolor white]
ask patches with [pxcor = 0 and pycor = -1][set pcolor white]
ask patches with [pxcor = 0 and pycor = -2][set pcolor white]
ask patches with [pxcor = 0 and pycor = -3][set pcolor white]
ask patches with [pxcor = 0 and pycor = -4][set pcolor white]
ask patches with [pxcor = 0 and pycor = -5][set pcolor white]
ask patches with [pxcor = 0 and pycor = -6][set pcolor white]
ask patches with [pxcor = -1 and pycor = -2][set pcolor white]
ask patches with [pxcor = -1 and pycor = -3][set pcolor white]
ask patches with [pxcor = -1 and pycor = -4][set pcolor white]
ask patches with [pxcor = -1 and pycor = -5][set pcolor white]
ask patches with [pxcor = -1 and pycor = -6][set pcolor white]
ask n-of Passengers patches with [pcolor = white][set pcolor white
sprout 1[
set color grey
set size 1
set shape "person"
set target patches with [pxcor = 3 and pycor = -3]
set trip 0
]]
create-bus Nbus[
set color red
set size 5
set xcor 3
set ycor -3
set shape "bus"
]
reset-ticks
end
to go
ask turtles[
move-to one-of patches with [pxcor = 3 and pycor = -3]
if any? neighbors with [pxcor = 4 and pycor = -3] and shape != "bus" ;; if passenger neighbors this patch, it dies
[
die]
]
tick
结尾
【问题讨论】: