【发布时间】:2022-10-18 01:05:16
【问题描述】:
我创建了一个代表 2 个巴士站的模型。此刻海龟登上公共汽车,然后公共汽车将开走。但是,我希望海龟的登机速度有所不同。换句话说,我希望上站的海龟比下站的海龟移动得更快(或者底部的比顶部的慢)。我不知道该怎么做......你们有什么建议吗?我的代码如下。提前致谢!
globals [time]
turtles-own [target]
breed [bus a-bus]
to setup
clear-all
;; above
ask patches with [pxcor = 2 and pycor = 6][set pcolor white]
ask patches with [pxcor = 2 and pycor = 5][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 = 5][set pcolor white]
ask patches with [pxcor = 1 and pycor = 6][set pcolor white]
ask patches with [pxcor = 3 and pycor = 5][set pcolor white]
ask patches with [pxcor = 3 and pycor = 6][set pcolor white]
ask patches with [pxcor = 4 and pycor = 5][set pcolor white]
ask patches with [pxcor = 4 and pycor = 6][set pcolor white]
ask patches with [pxcor = 5 and pycor = 5][set pcolor white]
ask patches with [pxcor = 5 and pycor = 6][set pcolor white]
ask patches with [pycor = 7][
set pcolor gray
]
;;below
ask patches with [pxcor = 2 and pycor = -6][set pcolor white]
ask patches with [pxcor = 2 and pycor = -5][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 = -5][set pcolor white]
ask patches with [pxcor = 1 and pycor = -6][set pcolor white]
ask patches with [pxcor = 3 and pycor = -5][set pcolor white]
ask patches with [pxcor = 3 and pycor = -6][set pcolor white]
ask patches with [pxcor = 4 and pycor = -5][set pcolor white]
ask patches with [pxcor = 4 and pycor = -6][set pcolor white]
ask patches with [pxcor = 5 and pycor = -5][set pcolor white]
ask patches with [pxcor = 5 and pycor = -6][set pcolor white]
ask patches with [pycor = -4][
set pcolor gray
]
;; passengers above
ask n-of Passengers_2 patches with [pcolor = white and pycor > 0][
sprout 1[
set color grey
set size 1
set shape "person"
set target patches with [pxcor = 3 and pycor = 8]
]]
;; passengers below
ask n-of Passengers_1 patches with [pcolor = white and pycor < 0][
sprout 1[
set color grey
set size 1
set shape "person"
set target patches with [pxcor = 3 and pycor = -3]
]]
;; bus above
create-bus Bus_2[
set color red
set size 5
set xcor 3
set ycor 8
set shape "bus"
set heading 90
]
;; bus below
create-bus Bus_1[
set color red
set size 5
set xcor 3
set ycor -3
set shape "bus"
set heading 90
]
reset-ticks
end
to check-in
ask turtles with [ycor < 0 ] [ ;; below
move-to one-of patches with [pxcor = 3 and pycor = -3]
if any? neighbors with [pxcor = 3 and pycor = -4] and shape != "bus" ;; if passenger neighbors this patch, it dies
[
die]
]
ask turtles with [ycor > 1 ] [ ;; above
move-to one-of patches with [pxcor = 3 and pycor = 8]
if any? neighbors with [pxcor = 4 and pycor = 8] and shape != "bus" ;; if passenger neighbors this patch, it dies
[
die]
]
tick
end
to drive
set time ticks
if time > 0 [
ask turtles with [pycor < 0 or pycor > 1][
forward 33
if any? turtles [ stop ]
]]
tick
end
to go
check-in
drive
tick
end
【问题讨论】:
-
要在速度上有差异,首先需要一个速度的概念。您使用
move-to,它会立即将海龟从当前位置“传送”到目的地。你需要让他们采取一系列小步骤 -
@LeirsW 感谢您的提示!起初我试图这样做,但我无法让它工作......关于如何做到这一点的任何建议?
-
@LeirsW如果我尝试将公共汽车设置为目标,海龟将随机移动到世界上,这是不应该发生的
-
您可以使用
face转向您希望他们去的公共汽车。你可以给他们一个名为speed的乌龟自己的参数,让他们每一步都向前走,如果他们与公共汽车的距离小于他们的速度值,就会到达