2016-05-16 4 views
1

Flockingモデルのコード例を修正して、遭遇したときに学校(群)を形成する魚を表し、残りのコードのロジックを使用して一緒に移動しようとしています。残念ながら、そのロジックを遵守するには、同じパッチを同時に使用する必要があります。Netlogo 1つのパッチで複数のカメの群れを変更する

to-report average-heading-towards-schoolmates ;; turtle procedure 

    let x-component mean [sin (towards myself + 180)] of schoolmates 
    let y-component mean [cos (towards myself + 180)] of schoolmates 
    ifelse x-component = 0 and y-component = 0 
    [ report heading ] 
    [ report atan x-component y-component ] 
end 

あなたに向けて何の見出しはありませんので、それがエラーを取得する「に向けて、自分の」最寄りの学校は、亀のランニングと同じパッチ上にある場合:問題は-に向けた-学友平均-見出しが報告中に生じます正確な場所。私は場所にいくつかの格差が存在することになるので、コードの先頭に

forward 0.001 

set xcor xcor - 0.001 

を追加しようとしましたが、それは助けにはなりませんでした。私がそれをしたいのは、 "検索"プロトコルを呼び出す見出しを決定できない場合です。

この問題を解決するためのあらゆる創造的なアイデアは非常に高く評価されます!

答えて

2

パッチが同じである場合のエラーチェックが必要です。あなたのモデルでは、エージェントが同じパッチに入っている状況で何をすべきかを検討する必要があります。以下のコードでは、それらを無視します。

towardsのドキュメントから:

注:エージェントから自分に見出しを求め、または 同じ場所にエージェント、ランタイムエラーが発生します。

to-report average-heading-towards-schoolmates ;; turtle procedure 

    let my-schoolmates schoolmates with [patch-here != [patch-here] of myself] 
    ifelse any? my-schoolmates 
    [ 
    let x-component mean [sin (towards myself + 180)] of my-schoolmates 
    let y-component mean [cos (towards myself + 180)] of my-schoolmates 
    report atan x-component y-component 
    ] 
    [report heading] 
end 

あなたの見出しの計算に同じパッチ上のカメを取り入れてみたいことがあります。

to-report average-heading-towards-schoolmates ;; turtle procedure 

    let x-component mean [ifelse-value patch-here != [patch-here] of myself [0] [sin (towards myself + 180)]] of schoolmates 
    let y-component mean [ifelse-value patch-here != [patch-here] of myself [0][cos (towards myself + 180)]] of schoolmates 
    ifelse x-component = 0 and y-component = 0 
    [ report heading ] 
    [ report atan x-component y-component ] 
end 
+0

大感謝マットそれはトリックをした、または少なくとも私が届かないように見えますもうエラーはありません。しかし、クイックコメントでは、コードの2番目のビットに小さな構文エラーがあります。 patch-here!= [patch-here]自分自身の を括弧で囲むか、コードチェック中にエラーが発生します。私はあなたのコードを編集することはできませんが、そのような小さなエラーhaha – Jesse001

関連する問題