【发布时间】:2017-11-18 12:05:48
【问题描述】:
我是初学者。我已经检查了编程指导字典。 我正在考虑一个两车道的道路(例如,道路 1、道路 2)模型。 而且我正在考虑一个模型,其中指定的补丁((10 0)和(20 2))指定的海龟停止10个滴答声。 但是,我不知道如何为每条道路编写和指定 xcor 和 ycor 的具体参数(例如道路 1 上的 xcor 和 ycor,道路 2 上的 xcor 和 ycor)。 而且我不知道如何在设置速度语法中编写和控制参数“速度”。 以下是样本小模型。为避免复杂化,此示例模型只有一条路。此示例模型失败,并且海龟不会在 patch(10 0) 处停止。 可能我需要你的建议。谢谢。
globals [ count-tick ]
turtles-own [ speed flag-A ]
to setup
clear-all
resize-world 0 50 min-pycor max-pycor
ask patches [ setup-road ]
reset-ticks
end
to setup-road
if ( pycor < 1 ) and ( pycor > -1 ) [ set pcolor white ]
end
to create-car
crt 1 [
set color blue
setxy min-pxcor 0
set heading 90
set speed 1
]
end
这是模型的主体。
to go
if (count turtles-on patch 0 0 = 0) [
create-car
ask (turtles-on patch 0 0) [
set flag-A FALSE
]
]
ask (turtles-on patch 10 0) [
set flag-A TRUE
set count-tick 10
]
if count-tick > 0 [
set count-tick count-tick - 1
ask (turtles-on patch 10 0) with [flag-A = TRUE]
[
set color red
set speed 0
]
]
if count-tick = 0 [
ask (turtles-on patch 10 0) with [flag-A = TRUE]
[
set speed 1
set flag-A FALSE
]
]
if (count turtles-on patch max-pxcor 0 > 0) [
ask min-one-of turtles [who][
die
]
]
set-speed
tick
end
这是控制速度的并行更新。
to set-speed
ask turtles with [ xcor < 10 ] [
let turtle-ahead one-of turtles-on patch-ahead 1
ifelse turtle-ahead = nobody
[ set speed 1
fd speed
]
[ set speed 0
]
]
ask turtles with [ 10 < max-pxcor ] [
let turtle-ahead one-of turtles-on patch-ahead 1
ifelse turtle-ahead = nobody
[ set speed 1
fd speed
]
[ set speed 0
]
]
end
【问题讨论】:
标签: timer counter netlogo flags