Netlogo:在途中阻止乌龟并让其他人假设

Netlogo: Stop a turtle in route and make others assuming

我创建了 3 辆汽车,但我只有 ID 为 0 和 1 的汽车的路线:

汽车 0 -> 路线 [4 3]

汽车 1 -> 路线 [7 6 5]

Car 2 -> route [] 因为我想把这辆车停下来备用

我想为汽车创建一个 crash? 变量,即 IF 达到 25 ticks,变量 crash?它是 TRUE,路线中的一辆车停...

在我的 go 程序中,我尝试将其放入,但仅 one-of :

to go
ask carr with [ not route-complete? and not crash?] [
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   if route = [] [
  set target spawn-target
  ]
  if target = nobody [
  set target item route-counter route
  ]
  face target
  ifelse distance target > 1 [
  fd 1
  ] [
  move-to target
   ifelse target != spawn-target [
    set route-counter route-counter + 1
  ] [
    set route-complete? true
  ]
  set target nobody
  ]
  if route-counter > length route - 1 [
  set route-counter 0
  set target spawn-target
  ]
  ]
  tick
  end 

应该只停one-of有路线的车,ID 2已经停的车不算。 因为我认为这段代码考虑了所有的汽车并选择一辆车停下来,但我只想停下来或者汽车 0 或 1。 怎么修?

那么,如何定义一辆车为备用车(ID为2的车),走停靠的车路线去走访走失的家园呢? 因为在 25 ticks 如果其中一辆汽车 0 或 1 停下来,肯定会有没有参观过的房子......

如果有人能帮助我完成无法开发的两个任务,那就太好了。谢谢

我认为最简单的方法可能是让 'crashes' 的汽车使用 sublist 索引 route 变量将其剩余路线传递给备用汽车-查看 dictionary definition 了解更多详情。为了尽可能少地更改您的代码,请尝试在 go 过程的开头插入以下代码(代码注释提供更多详细信息,下面是完整的 go 过程):

to go
  ; only run this chunk if ticks = 25
  if ticks = 25 [
    ask one-of carr with [ not crash? and not route-complete? ] [
      ; get one of the still moving cars to:
      ; set crash? to true, change color to yellow
      ; for easy visibility
      set crash? true
      set color yellow
      ; make a temporary variable to hold the remaining house
      ; targets using sublist
      let remaining-route sublist route route-counter ( length route )
      ask one-of carr with [ route = [] ] [
        ; have the 'spare' care take over the remaining-route,
        ; set route-complete to false, and set the current
        ; target to 'nobody' so that the other conditions for
        ; movement are satisfied
        set route remaining-route
        set route-complete? false
        set target nobody
      ]
    ]
  ]


  ;; ask carr with route-complete set to false
  ask carr with [ not route-complete? and not crash? ] [
    ;for the spare car not to move
    if route = [] [
      set target spawn-target
    ]
    if target = nobody [
      set target item route-counter route
    ]

    face target
    ifelse distance target > 1 [
      fd 1
    ] [
      move-to target
      ifelse target != spawn-target [
        set route-counter route-counter + 1
      ] [
        set route-complete? true
      ]
      set target nobody
    ]
    ;; If the route counter would index outside of the
    ; list boundaries, reset it to 0
    if route-counter > length route - 1 [
      set route-counter 0
      set target spawn-target
    ]
  ]
  tick
end

请注意,按原样,活跃的 carr 可以在技术上(很少)在 ticks = 25 之前完成他们的路线。为避免这种情况,请在路线完成时停止模型或工作换个方式。