【问题标题】:netlogo turtle search function getting stuck in loop Netlogonetlogo 海龟搜索功能陷入循环 Netlogo
【发布时间】:2015-04-17 14:11:19
【问题描述】:

我有一个海龟搜索功能,可以在自己前面的直线上搜索“首选补丁”一段设定的距离。我创建了他们使用循环搜索的补丁数组。代码经常卡在循环中(我认为!)。我不确定为什么会发生这种情况...我想编写代码告诉海龟在补丁中搜索首选补丁,如果没有降落在搜索区域。如果不存在首选补丁,则在搜索区域中的任何补丁上。

海龟并不总是移动,所以我的代码显然有问题。

let move-distance random 20
loop [set search-area (patch-set patch-ahead move-distance)
set move-distance move-distance - 1
if move-distance = 1 [stop]]
let preferred-patches search-area with [flight-tendency = 0.05]
ifelse any? preferred-patches [
ifelse random-float 1 < 0.7 [
  set target one-of top-patches move-to target] 
[set target one-of other-patch move-to target]]
[set target one-of other-patch move-to target]

【问题讨论】:

    标签: netlogo agent


    【解决方案1】:

    random 20 可能返回 0 或 1,然后您在循环内对 move-distance 执行的第一件事就是从中减去 1,因此 move-distance = 1 检查将失败,因为它已经低于 1。

    尝试将move-distance = 1 替换为move-distance &lt;= 1,和/或将random 20 替换为2 + random 18

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 2013-11-14
      • 2016-03-11
      • 2018-04-11
      • 2016-09-23
      • 1970-01-01
      相关资源
      最近更新 更多