我如何为每个动作设置概率?

how can i set a probability for each action?

我有一些海龟在四处张望。对于他们得到的每个邻居,他们保存 "output-heat" 的值。具有最高值的补丁将获得最高概率,而最低值将获得最低概率。我想让乌龟移动到另一个补丁。移动应该取决于概率。

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

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]

 ]

你需要把最后的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] ] ] ] ] ] ] ]

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