現在、特定の道を歩いている人々のためのモデルを構築しています(道路パッチ、色=白)。エージェントの動きは白いパッチでのみ制限され、黒いパッチに遭遇すると180度回転します。Netlogo:見出しを丸める方法180 180 270 360のみ
私が見つけた問題は、エージェントの見出しを設定しようとしたときでした。私は見出しが最寄の赤いパッチ(目的地)まで歩いしたいが、私は使用している場合:MIN-1-の[pcolorの=赤]とパッチに向かって
セット[自分を遠ざけます] <
エージェントはパッチから移動しません。上記のコードで生成された "見出し"は-360〜360の小数点以下の値を持つことが判明しました。私が作成した歩行手順では、90(-360、-180 ... 90,180,270,360)の倍数の見出ししか使用できません。これは私のウォーキング法の完全なコードです:
globals [ flagl flagr ]
ask agents [
;reset flag
set flagr 0
set flagl 0
; check and note if there is a path on the left or the right
ask patch-left-and-ahead 90 1 [if (pcolor = white) [set flagl 1]]
ask patch-right-and-ahead 90 1 [if (pcolor = white) [set flagr 1]
]
;in T-junction, decide to turn left or right (random)
if((flagl = 1) and (flagr = 1))
[
ifelse random 100 > 50
[set heading heading - 90]
[set heading heading + 90]
]
;if it's only applicable to turn right, then turn right
if((flagl = 0) and (flagr = 1)) [set heading heading + 90]
;if it's only applicable to turn left, then turn right
if((flagl = 1) and (flagr = 0)) [set heading heading - 90]
;return if there's no mor path
if [pcolor] of patch-at-heading-and-distance heading 1 = black [rt 180]
;agent movement
**;face min-one-of patches with [pcolor = red ] [ distance myself ]**
fd 1
;stopping procedure
if [pcolor] of patch-here = red [fd 0]
]]
私はこのような#1によって生成された見出しを丸めることを試みた:
let direction heading towards min-one-of patches with [pcolor = red ] [ distance myself ]
if direction != mod 90
set direction 90 * round(arah/ 90)
ましょう「以来、それはエラー通知を与えるしかし、 "コマンドは、そのような入力を取ることはできません。
これは私が構築されているマップのスクリーンショットです: Map
をこの問題を解決するためのすべてのヘルプは非常歓迎です。ありがとうございました!