我的问题是我定义了一个要检查的补丁集,称为“左上”我希望汽车在前面只要左侧补丁集中没有汽车时移动到另一条车道,如果汽车在内侧车道上,并且没有车辆在左边但是在右边的类似补丁中,车辆可以移回到外侧车道。
我尝试过这种编码,但出于某种原因,汽车没有超车,偶尔会占用相同的空间,我不确定我是否使用ifelse声明错误,我怎么能让一辆车超过拿另一个?
to control-speed01
let in-lane (patch-set patch-ahead 2 patch-ahead 1 )
let car01-ahead one-of cars01-on in-lane
let on-left (patch-set patch-left-and-ahead 90 1 patch-left-and-ahead 45 1.5 patch-left-and-ahead 135 1.5)
let on-right (patch-set patch-right-and-ahead 90 1 patch-right-and-ahead 45 1.5 patch-right-and-ahead 135 1.5)
ifelse car01-ahead = nobody [
ifelse speed < maxSpeed [set speed speed + acceleration] [set speed speed - deceleration]
]
[
ifelse [speed] of car01-ahead = 0 [ifelse turtles-on on-left = nobody [move-to patch-left-and-ahead 90 1][set speed 0]][
ifelse [speed] of car01-ahead >= maxSpeed [
set speed maxSpeed
set speed speed - deceleration
][
set speed speed
]]
ifelse [speed] of car01-ahead = 0 [ifelse turtles-on on-right = nobody [move-to patch-right-and-ahead 90 1][set speed 0]][
ifelse [speed] of car01-ahead >= maxSpeed [
set speed maxSpeed
set speed speed - deceleration
] [
set speed speed
]]]
end