限制海龟的活动

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

我正在处理导入 Netlogo 的数据集(栅格类型)。我必须确保鸟类(在本例中为 2 类鸟类)不会离开输入区域(因为它们在输入区域之外和内部移动)。我按以下方式规定了鸟类的移动: 不过我想请问有没有更简单的方法?还是我的处理方式没问题?

to move-aves2 
  pen-down 
let target one-of patches with [pcolor = 8 or pcolor = 68 or pcolor = 79 or pcolor = 49 or pcolor = 28 ]
  if target != nobody [ face target
    fd 8 
     set energy energy - 17.19 ] 

 if any? patches in-radius 10 with [borde-negro = 1] [
  let black-patches patches with [pcolor = 130]
  let safe-patches patches with [pcolor != 130]
  let target-patch min-one-of safe-patches [distance myself]
  ifelse any? black-patches in-radius 10 [
      face min-one-of black-patches [distance myself]
      lt 180 
    fd 1  
  ] [
    face target-patch 
    fd 9
  ]
]

对我的问题的建议,因为虽然代码有效,但我不知道我是否做得正确

gis netlogo patch
1个回答
0
投票

一项改进是对

patches with [pcolor = 8 or pcolor = 68 or pcolor = 79 or pcolor = 49 or pcolor = 28 ]
black-patches
safe-patches
使用全局变量而不是局部变量。这将使您的代码更简单并且(可能)执行速度更快。

如果补丁颜色从未改变,请在设置中执行以下操作:

set colored-patches patches with [pcolor = 8 or pcolor = 68 or ...
set black-patches patches with [pcolor = 130]
set safe-patches patches with [pcolor != 130]

如果色块颜色确实发生变化,只需重复这些

set
语句即可。

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