如何在特定区域中隔离NetLogo中的海龟

时间:2014-06-09 09:18:37

标签: netlogo

在NetLogo中,是否有可能创建一种围栏区域(畜栏),在这种区域中我可以隔离n只生病的海龟(不是无限制的),而健全的海龟无法访问它? 如果是的话,我怎么能在那里移动生病的海龟呢?我怎样才能阻止神智海龟到达那里?

3 个答案:

答案 0 :(得分:1)

我所做的就是隔离一堆补丁。

假设您的原点位于框架的中心。而且您的max-xcor为30,而您的max-ycor也是30。

将此地图作为参考。

NetLogo workspace

现在说,生病的海龟必须在第一象限,健康的海龟必须在第三象限。

您希望ask turtles with生病状态显示在右上角face。这将是坐标(30,30),然后他们应该检查它们是否在指定区域。如果没有,继续前进。由于您希望它们围绕第一象限进行隔离,因此您希望制定一个程序使它们在进入后随机移动

同样适用于健康的海龟,请他们face坐标-30,-30然后ask他们随机进行forward步骤,然后检查他们是否在指定区域。如果没有,继续前进。

  • 如何防止病龟进入病龟区?

询问每只健康的海龟它们的坐标是什么,如果这些坐标非常接近病龟的区域,让它们面向另一条路(比如随机坐标)。

  • 如何知道他们是否非常接近病龟?

用if!

Ifelse [turtles.coordinateX + 5 >= 30 && turtle.coordinateY + 5 >= 30] [true][false] < This means they're close by 5 patches!

当然在netlogo中重写。

这里也有很多帮助。 http://ccl.northwestern.edu/netlogo/docs/

答案 1 :(得分:0)

这可能是我认为更简单的方法

First design the quadrants during setup :


ask patches with [ pxcor <= max-pxcor and pxcor > 0  and pycor > 0]
  [
    set pcolor red
    set quadrant 1

  ]

  ask patches with [ pxcor >= min-pxcor and pxcor < 0  and pycor > 0]
  [
    set pcolor blue
    set quadrant 2
  ]

  ask patches with [ pxcor <= max-pxcor and pxcor > 0  and pycor < 0]
  [
    set pcolor green
    set quadrant 3
  ]

  ask patches with [ pxcor >= min-pxcor and pxcor < 0  and pycor < 0]
  [
    set pcolor yellow
    set quadrant 4
  ]
Now on 'go'
to go
  ask turtles with [gender = "Female"] [
    let p one-of patches with [quadrant = 1]
    move-to p
  ]
  ask turtles with [gender = "Male"] [
    let p one-of patches with [quadrant = 4]
    move-to p
  ]
end

答案 2 :(得分:0)

最简单的方法是创建一个patch-set并将其标记为医院。为此,您需要:

globals [hospital]

to setup
  ....
  set hospital patches with [pxcor < -10 and pycor < -10 ]
  ...
end

然后,只要您有乌龟移动,就可以让乌龟去医院咨询。例如:

ask turtles
[ face one-of hospital
  forward 1
]

或者您可以跳到不在医院的随机patch处:

ask turtles [ move-to one-of patches with [not member? self hospital ]]

这里是将其组合在一起的完整模型:

globals [hospital]

to setup
  clear-all
  create-turtles 20
  set hospital patches with [pxcor < -10 and pycor < -10 ]
  ask hospital [set pcolor red]
  ask turtles
  [ move-to one-of patches with [not member? self hospital]
  ]
end