2015-04-17 43 views
2

我有一個搜索功能的海龜搜索'首選補丁'在自己面前的直線設置的距離。我使用循環創建了他們搜索的補丁數組。代碼經常卡在循環中(我想!)。我不知道爲什麼會發生這種情況......我想編碼告訴海龜通過補丁搜索一個首選補丁,如果不是在隨機補丁上着陸,有70%的機率着陸在其中一個補丁上搜索區域。如果在搜索區域中的任何補丁上都不存在首選補丁。netlogo烏龜搜索功能陷入循環Netlogo

海龜並不總是移動,所以我的代碼顯然是非常錯誤的。

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] 

回答

1

random 20可能返回0或1,然後你做move-distance循環內的第一件事就是從它減去1,是因爲它已經低於1

嘗試更換move-distance = 1檢查將失敗move-distance = 1move-distance <= 1,和/或用2 + random 18代替random 20