网传如何要求乌龟等到别人乌龟超过特定的距离时才会出现

问题描述 投票:0回答:1

我想在Netlogo中写一段代码,让乌龟等待一定的时间(例如:2秒),如果他的邻居小于一定的距离,当他和邻居之间的距离超过这个距离后,这只乌龟就可以开始移动了。这是我的一段代码。

我对乌龟的初始设置:

;;send people back to where they come from
  ask turtles [
    move-to one-of road with [not any? other turtles in-radius 4]
  ]

要求乌龟移动

  to move
           face best-way-to goal
           ifelse patch-here != goal
            [ 
              ifelse how-close < 2
              [wait 2 fd 1]
              [fd 1]
            ]
            [stop]
    end

to-report keep-distance
   set close-turtles other turtles-on (patch-set patch-here neighbors4)
   ifelse any? close-turtles
       [set how-close distance min-one-of close-turtles [distance myself]]
       [set how-close 100] ;this means cannot find neighbours around this people
   report how-close
end

但这并没有给我我想要的东西。有人知道如何在Netlogo中实现这个功能吗?任何帮助是真的appreaciated。谢谢!我想在Netlogo中写代码。

netlogo agent-based-modeling
1个回答
1
投票

使用的问题 wait 是模型会暂停,所以其他乌龟也不会移动,也不能移动走。如果你想让一只乌龟只在没有人靠近的时候才移动,可以尝试将。

to move
  face best-way-to goal
  ifelse patch-here != goal
  [ 
    ifelse how-close < 2
    [wait 2 fd 1]
    [fd 1]
  ]
  [stop]
end

替换成

to move
  face best-way-to goal
  if patch-here != goal and how-close >= 2
  [ forward 1
  ]
end

也就是说,你不需要 ifelse 建设,你可以使用 if 并只需在条件合适时才动身。

© www.soinside.com 2019 - 2024. All rights reserved.