在Netlogo中创建特定路径,让海龟遵循

时间:2017-03-28 19:51:52

标签: path netlogo

我正在创建一个关于动物园的Netlogo模型。我需要我的动物园客人(多只乌龟)沿着一条环形路径开始,每隔24个蜱虫在动物园入口处开始(我的模型中有1个小时是1小时)。它必须移动笼养动物的笼子,因为我无法让我的客人进入动物区域。路径不必是快速或最短的,我只需要乌龟不要偏离它。我宁愿不使用GIS来创建一条路径。

我的世界尺寸在两个方向都是-30到30并且不会环绕。

笼子的下落描述如下:

patches-own [ tigerhabitat?
              flamingohabitat?
              monkeyhabitat?
              hippohabitat?
              giraffehabitat?
            ]

to create-habitats
  ask patches with [ pxcor < -12 and pycor > 23 ]
  [ set tigerhabitat? true
    set pcolor green ]

  ask patches with [ pxcor > 20 and pycor > 20 ]
  [ set hippohabitat? true
    set pcolor blue ]

  ask patches with [ pxcor > 18 and pycor < 15 and -1 < pycor ]
  [ set flamingohabitat? true
    set pcolor 96 ]

  ask patches with [ pxcor > -10 and pxcor < 10 and pycor < 10 and -10 < pycor ]
  [ set monkeyhabitat? true
    set pcolor green ]

  ask patches with [ pxcor < -12 and pycor < -20 ]
  [ set giraffehabitat? true
    set pcolor 67 ]

end

1 个答案:

答案 0 :(得分:1)

Paula-从您的评论中我认为我理解得更好,谢谢。控制海龟可以移动的一种简单方法是使用逻辑运算符来排除他们认为&#34;&#34;他们一起走。对于你想要的基本(非路径)版本,你可以告诉海龟他们只能移动不是笼子的补丁。您可以设置一个仅修补程序的变量,明确说明补丁是否被关在笼中,但在上面的示例中,所有非笼式补丁都是黑色的 - 您可以使用它来告诉海龟他们应该只走到路径上是黑色的。例如,您可以将以下过程添加到您的代码中:

to setup
  ca
  reset-ticks
  crt 10 [
    setxy -25 0
  ]
  create-habitats
end


to go
  exclude-cage-walk
  tick
end


to exclude-cage-walk
  ask turtles [
    rt random 30 - 15
    let target one-of patches in-cone 1.5 180 with [ pcolor = black ]
    if target != nobody [
      face target
      move-to target
    ]
  ]
end

你可以看到,在前进之前,每只乌龟评估它选择的move-to补丁是否为黑色,如果它黑色,乌龟将不会移动那里。当然,你必须修改它以满足你的需要,并让乌龟走在一个单向的循环,但这是一个约束龟运动的简单方法。

相关问题