【发布时间】: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]
【问题讨论】: