Merge traffic lanes in NetLogo simulation

旧巷老猫 提交于 2019-12-03 21:45:02

You wrote:

if ycor = -10.75
[
  rt 45
  fd speed 
  ;;;fd 5.1
  ifelse ycor = -14.25
  [
    lt 45
    fd speed 
  ]
  [
    fd speed 
  ]
]

If I leave out some things that don't matter, that's:

if ycor = -10.75
[
  ...
  ifelse ycor = -14.25
  [
    ...

The ifelse is inside the if, so it only runs if ycor is -10.75. But how can ycor be equal to -10.75, and equal to -14.25? It can't, so the second condition never triggers.

Perhaps the structure you intended is:

ifelse ycor = -10.75
[
  ...
]
[
  ifelse ycor = -14.25
  [
    ...

this is how you express "if ycor is -10.75, do this; but if ycor is -14.25, do that instead".

I think your problem is that ycor never exactly equals -14.25 unless it starts at -14.25. This is because the car moves forward and only checks its position after the movement, so it might move to -14.5 or -14.0 or some other value that is not -14.25. In that case, you want it turn left whenever it gets close to the -14.25 lane. Try something like this:

ifelse ycor = -14.25
[ fd speed ]
[ if heading = 90 [ rt 45 ]
  fd speed
  if ycor <= -12.5
  [ set heading
    set ycor -14.25
  ]
]
Bùi Dũng
 ifelse ycor = -14.25 [
    fd speed
    ]
    [
    rt 45
    fd speed
    ifelse ycor = -14.25
       [
       lt 45
       fd speed
       ]
       [
       fd speed
       ]
    ]
   ]
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!