1

我有一些海龟正在环顾四周。对于他们拥有的每个邻居,他们保存“输出热量”的值。具有最高值的补丁将获得最高概率,最低值将获得最低概率。我希望乌龟移动到另一个补丁。移动应该取决于概率。

我的代码看起来像这样,但它不能正常工作:

ask turtles-here[

 let temp_ahead [(output-heat + 1)^ Freedom] of patch-at 0 1
 let temp_right_ahead [(output-heat + 1)^ Freedom] of patch-at 1 1
 let temp_right [(output-heat + 1)^ Freedom] of patch-at 1 0
 let temp_right_back [(output-heat + 1)^ Freedom] of patch-at 1 -1
 let temp_back [(output-heat + 1)^ Freedom] of patch-at 0 -1
 let temp_left_back [(output-heat + 1)^ Freedom] of patch-at -1 -1
 let temp_left [(output-heat + 1)^ Freedom] of patch-at -1 0
 let temp_left_ahead [(output-heat + 1)^ Freedom] of patch-at -1 1  





set temp_ahead_kumulativ  temp_ahead 
set temp_right_ahead_kumulativ  (temp_ahead_kumulativ + temp_right_ahead)
set temp_right_kumulativ  (temp_right_ahead_kumulativ + temp_right)
set temp_right_back_kumulativ (temp_right_kumulativ + temp_right_back)
set temp_back_kumulativ  (temp_right_back_kumulativ + temp_back)
set temp_left_back_kumulativ  (temp_back_kumulativ + temp_left_back)
set temp_left_kumulativ  (temp_left_back_kumulativ + temp_left)
set temp_left_ahead_kumulativ  (temp_left_kumulativ + temp_left_ahead)

set propability_number (random-float (temp_left_ahead_kumulativ))

 if propability_number < temp_ahead_kumulativ [right 0]
 if propability_number < temp_right_ahead [right 45]
 if propability_number < temp_right_kumulativ [right 90]
 if propability_number < temp_right_back_kumulativ [right 135]
 if propability_number < temp_back_kumulativ [right 180]
 if propability_number < temp_left_back_kumulativ [left 135]
 if propability_number < temp_left_kumulativ [left 90]
 if propability_number < temp_left_ahead_kumulativ [left 45]

 ]
4

1 回答 1

2

您需要将if最后的所有语句变成ifelse语句。按照您的设置方式,较低的随机数将使海龟转向多个方向。

ifelse propability_number < temp_ahead_kumulativ [right 0] [
ifelse propability_number < temp_right_ahead [right 45] [
....
ifelse propability_number < temp_left_kumulativ [left 90]
[left 45] ] ] ] ] ] ] ]

注意:我可能弄错了 ] 的数量,您需要确保当光标位于最后一个时,第一行顶部的 [ 突出显示。

于 2015-10-28T19:32:22.410 回答