我正在重用Netlogo上的Traffic 2 Lanes示例,以尝试模拟智能自动驾驶汽车如何围绕普通汽车运行。 1-5级有5个不同的自治级别。我有一个称为“自治程度”的滑块,但是现在要做的只是将具有更大自治程度的汽车的所有颜色更改为红色,我将在下面发布。当我将自动驾驶级别设置为4时,当用户使用滑块确定汽车的总数量时,如何使用道路上一半的汽车的颜色? 5级汽车,例如黄色。
这是创建所有汽车的代码
to create-or-remove-cars
; make sure we don't have too many cars for the room we have on the road
let road-patches patches with [ member? pycor lanes ]
if number-of-cars > count road-patches [
set number-of-cars count road-patches
]
create-cars (number-of-cars - count turtles) [
set color car-color
move-to one-of free road-patches
set target-lane pycor
set heading 90
set top-speed 0.5 + random-float 0.5
set speed 0.5
set patience random max-patience
]
if count turtles > number-of-cars [
let n count turtles - number-of-cars
ask n-of n [ other turtles ] of selected-car [ die ]
]
end
这是我现在拥有的自治级别滑块的代码
to set-level-of-autonomy
ask cars
[if level-of-autonomy > 0
[ask cars [ set color red ]]
]
end
所以可以说,用于汽车数量的滑块设置为40,我希望20辆汽车成为5种不同级别的特定颜色,如何做到这一点,任何帮助都会很棒,尤其是来自用户查尔斯。
ask turtles [
if [count turtles with [color = blue] < number-of-cars / 2][
set color blue
]
]