我一直在为一个双线路场景拍摄一个基本的代码,我尝试了下面的编码,我认为它会起作用,但是汽车仍然不会过度,我不确定是否存在矛盾声明。到目前为止,这段编码将加速汽车并在汽车停在前面时停止它们但由于某种原因不会移动到另一条车道。任何想法?
let in-lane (patch-set patch-ahead 2 patch-ahead 1.5 patch-ahead 1 ); patch-
left-and-ahead 26 1 patch-right-and-ahead 26 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)
; set meaning "road-all" = "road-right" "road-left"
ifelse car01-ahead = nobody [
ifelse speed < maxSpeed [set speed speed + acceleration] [set speed speed - deceleration]
]
[
ifelse [meaning] of patch-left-and-ahead 90 1 != "road-left"
[ifelse turtles-on on-left = nobody
[move-to patch-left-and-ahead 90 1]
[ifelse [speed] of car01-ahead = 0
[set speed 0] [
ifelse [speed] of car01-ahead >= maxSpeed
[ set speed maxSpeed
set speed speed - deceleration]
[ set speed maxSpeed
set speed speed - deceleration ]]]][
ifelse [meaning] of patch-right-and-ahead 90 1 != "road-left"
[ifelse turtles-on on-left = nobody
[move-to patch-right-and-ahead 90 1]
[ifelse [speed] of car01-ahead = 0
[set speed 0] [
ifelse [speed] of car01-ahead >= maxSpeed
[ set speed maxSpeed
set speed speed - deceleration]
[ set speed maxSpeed
set speed speed - deceleration ]]]][ set speed maxSpeed
set speed speed - deceleration ]
]]
答案 0 :(得分:1)
<a href="./leitor.do?numero=20090&keyword=ministro&anchor=5975889&origem=busca" class="edition" title="Folha de S.Paulo">
<figure>
<img src="https://acervo.folha.uol.com.br/files/flip/11/89/58/97/5975889/140/5975889.jpg" width="180" height="312.4">
</figure>
<h3>31.dez.2014</h3>
<p>
país. Poder Novo <b>ministro</b> diz que Congresso irá ?expurgar? culpados futuro articulador polí
</p>
<small>
Folha de S.Paulo, Ano 94 - N° 20.090<br>
A1 - 1 ocorrência
</small>
</a>
始终为false,因为turtles-on on-left = nobody
始终返回代理集,而turtles-on
不是代理集。 nobody
出现在预期单个代理但没有可用的情况下;与代理集分开。
相反,请写nobody
或更好turtles-on on-left = no-turtles
。
在这种情况下,我能够通过观察代码来发现问题(或者至少是一个问题)。如果我无法做到这一点,我建议在代码中添加not any? turtles-on on-left
语句,以检查变量的值是否符合您的预期,以及您希望采用的分支是否实际被采用。该技术会发现print
总是错误的。