私はタートルズ(Movers)の束をゲートを通ってゲートに行き、白い壁を避けようとします。どういうわけか、モデルは数回実行した後にフリーズします。 Goボタンは黒のままで、青い円は永遠に変わります。 MSGのエラーはありません。それは "ムーブ・ムーバー"機能内で何らかの計算に詰まらなくてはならないが、なぜそれを判断することはできない。NetLogo:モデルにはエラーメッセージが表示されません
クラッシュを生成する簡単なコードを追加しました。実行するために&ペーストをコピーしてください。ワールドラップを無効にする。 「num-movers」変数のスライダを含めます。
breed [ movers mover ]
movers-own [ steps ] ; Steps will be used to determine if an agent has moved.
to setup
clear-all
reset-ticks
ask patches [ set pcolor green ]
basic-pattern
end
to basic-pattern ; sets up gate and wall
let wallXCor 16 ; sets a white line to determine the inside & outside of the gate
repeat 33 [
ask patch wallXCor 0 [ set pcolor white ]
set wallXCor wallXCor - 1
]
ask patches with [ pycor > 0 ] [ set pcolor lime ] ; sets the outside of the gate to another color (lime)
; changes colour of the center to lime to create a passable opening
ask patch 0 0 [ set pcolor lime ]
ask patch 1 0 [ set pcolor lime ]
ask patch -1 0 [ set pcolor lime ]
end
to distribute-agents ; Distributes the Movers outside the gate based on the patch color lime. The number needs to be set via slider "num-movers"
repeat num-movers [
ask one-of patches with [ pcolor = lime and pycor > 2 and any? turtles-here = false ] [
sprout-movers 1 [ set color red set shape "circle" facexy 0 -12 ] set num-movers num-movers- 1 ]
] end
to go
move-movers
tick
end
to move-movers ; reset the steps variable and facing
ask movers [ set steps steps + 1 ]
ask movers [ facexy 0 -3 ]
; following lines checks if next patch to be steped upon is "legal".
while [ any? movers with [ steps > 0 ] ] [
ask movers with [ steps > 0 ] [
ifelse is-patch? patch-ahead 1
and not any? turtles-on patch-ahead 1
and [ not member? pcolor [ white brown ] ] of patch-ahead 1
[
fd 1
set steps steps - 1
] [ dirchange ]
]
]
end
to dirchange ;If not able to move to next patch change direction to allow a step backwards.
if (pxcor <= 0 and ycor >= 0) [ facexy 1 3 ] ;fd 1 set steps steps - 1]
if (pxcor >= 0 and ycor >= 0) [ facexy -1 3 ] ;fd 1 set steps steps - 1]
end
これらの状況でwhileループの代わりに何を使用することをお勧めしますか? –
条件が満たされない限り、再帰的に呼び出すことができるコマンドプロシージャを書くことをお勧めします。通常、デバッグするのがずっと簡単になります。 –