好的,我已经重新建模了一段时间,以演示智能汽车在现实世界的高速公路上的表现。我有一个滑块,可以改变道路上一半汽车的颜色,我希望这些汽车有自己的设置,而其他汽车的行为是相同的。这是改变颜色的代码。
这是汽车品种的设置过程和变量。
cars-own [
If after I run the go procedure and I wanted the specific cars that have their colours changed to go around the road differently either based on the cars speed or the drivers patience to switch lane how do I specifically identify them?
I tried an If statement where I say if the car's colour isn't orange red or yellow do .....
but that doesn't work. 发布于 2020-03-13 04:57:47
一种方法是定义另一种汽车,然后让那些改变了颜色的汽车也改变它们的品种。然后,您可以引用所有这类汽车的新品种名称。例如,
breed [cars2 car2]
cars2-own [
the same variables as cars-own
]
....
to set-level-of-autonomy
let num-change number-of-cars / 2 - count turtles with [color = orange or color = red or color = yellow]
ask n-of num-change cars
[ if level-of-autonomy = 0 [set color blue set breed cars2]
if level-of-autonomy = 1 [set color blue + 1.0 set breed cars2]
if level-of-autonomy = 2 [set color cyan set breed cars2]
if level-of-autonomy = 3 [set color turquoise set breed cars2]
if level-of-autonomy = 4 [set color green set breed cars2]
if level-of-autonomy = 5 [set color lime set breed cars2]
]
end当cars将它们的breed更改为cars2时,只要这些变量也被列为cars2-own变量,它们“自己的”变量的值就会保持不变。您现在可以分别引用cars和cars2。请注意,如果所有汽车都有五个指定的自主性级别值中的一个,您可以简化一点。
to set-level-of-autonomy
let num-change number-of-cars / 2 - count turtles with [color = orange or color = red or color = yellow]
ask n-of num-change cars
[ if level-of-autonomy = 0 [set color blue]
if level-of-autonomy = 1 [set color blue + 1.0]
if level-of-autonomy = 2 [set color cyan]
if level-of-autonomy = 3 [set color turquoise]
if level-of-autonomy = 4 [set color green]
if level-of-autonomy = 5 [set color lime set]
set breed cars2
]
end另一种方法是定义一组颜色变化的汽车,而不是新品种的汽车。
globals [changed-cars]
......
let changed-cars no-turtles
........
to set-level-of-autonomy
let num-change number-of-cars / 2 - count turtles with [color = orange or color = red or color = yellow]
ask n-of num-change cars
[ if level-of-autonomy = 0 [set color blue]
if level-of-autonomy = 1 [set color blue + 1.0]
if level-of-autonomy = 2 [set color cyan]
if level-of-autonomy = 3 [set color turquoise]
if level-of-autonomy = 4 [set color green]
if level-of-autonomy = 5 [set color lime set]
set changed-cars (turtle-set changed-cars self)
]
end每辆更改的汽车都会将自己放在代理集changed-cars中。现在,cars指的是所有的汽车,而changed-cars只指那些发生了变化的汽车。changed-cars是cars的一个子集。有了breeds,这两个品种就相互独立了。
https://stackoverflow.com/questions/60660249
复制相似问题