2016-10-23 9 views
2

ランダムに動いているが特定の障害を回避しているエージェントの簡単なシミュレーションを作成しようとしています。私は彼らが行った場所の座標を保存して、再びそこに行かないようにします。これは私がこれまで持っていたものの一部です:NetLogoのリストにエージェント座標を格納する

to move-agent 

    let move random 3 
    if (move = 0) [] 
    if (move = 1)[ left-turn ] 
    if (move = 2)[ right-turn ] 

    set xint int xcor ;;here i'm storing the coordinates as integers 
    set yint int ycor 

    set xylist (xint) (yint) 

    go-forward 

end 

to xy_list 
    set xy_list [] 
    set xy_list fput 0 xy_list ;;populating new list with 0 
end 

しかし、それは私に "SET expected 2 inputs"エラーを与え続けます。誰もこれで私を助けることができますか?

答えて

3

xy_listが変数とカメの変数の両方として誤って使用されているようです。

私はxy_listプロシージャの必要性を見ません - それはタートルの変数として保持します。 xy_listはカメ、自分のリストにあることを確認してください:あなたは亀を作成するときに

turtles-own [xy_list]

は空のリストにそれを初期化します。例えば:

crt 1 [set xy_list []]

、あなたが彼らの現在のXCORとしての位置、ycorリストを追加することができたときカメの移動:

set xy_list fput (list int xcor int ycor) xy_list 

あなたは、その座標既に存在するかどうかを確認する必要があります。リストに移動する前に

しかし、整数座標を使用しているので、亀の歴史を追跡するためにパッチセットを使用する方がずっと簡単です。これを試すことができます:

turtles-own [history] 

to setup 
    ca 
    crt 3 [set history (patch-set patch-here) pd] 
end 

to go 
    ask turtles [ 
    let candidates neighbors with [not member? self [history] of myself] 
    ifelse any? candidates 
     [move-to one-of candidates stamp 
     set history (patch-set history patch-here)] 
     [die] 
    ] 
end 
関連する問題