布局与交通灯的交叉点。我希望汽车停在红灯和灯光下去xanh.thi我应该用于汽车算法可以识别灯光的颜色
我使用了光布局算法如下
to draw-stop-light
ifelse stop-light = "north"
[
ask patch -7 12 [set pcolor green ]
ask patch 10 10 [ set pcolor red ]
ask patch -10 -10 [ set pcolor red ]
]
[
ask patch -7 12 [ set pcolor red ]
ask patch 10 10 [ set pcolor green ]
ask patch -10 -10 [ set pcolor green ]
]
end
答案 0 :(得分:1)
这是一个比Stack Overflow更适合NetLogo用户组here的问题,因为您询问如何编写定义不明确的规范。例如,用户组可能会指向您类似的模型。 Stack Overflow实际上是关于修复代码的特定问题。但是,在问题被删除之前,您可以开始使用这些内容。
将您想要发生的事情细分为非常小的步骤,然后对每一步进行编码。步骤将类似于:
不要试图写出整件事。相反,一次写一个位,测试是否有效。这是第一位的一些近似代码:
ask cars
[ ifelse heading = 180 and ycor > 20 and ycor < 25 and not stop-flag
[ if [ pcolor of patch -7 12 ] = red [ set stop-flag true ] ]
[ ... (cars from other directions)
]
ask cars
[ forward speed
if stop-flag and ... (on intersection patches)
[ ... (move backwards to be outside the intersection)
set stop-flag false
]
]
答案 1 :(得分:1)
patch-right-and-ahead
(http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patch-lr-and-ahead)在这里很有用。也许是这样的事情:
if [pcolor] of patch-right-and-ahead 90 1 = red
[ set speed 0 ]