2017-12-07 3 views
0

私の変数は私のカメのラベルを継承します。変数は私のカメのラベルをinhrit可能です

私はそれらのルートを作って、彼らが最後に訪れた場所を覚えておきたいと思っています。

したがって、チェーンはチェーンの次の場所に進みます。

ifelse last_place = home 

[set place min-one-of (turtles with [label = "mall"])[distancemyself]] 

[set place min-one-of (turtles with [label = "home"])[distancemyself]] 

私は

を追加したい

place = one-of turtles with [label = "mallI] 

場合、私はここに私の実際のコードを使用するカントが、うまくいけば、あなたはその要旨

を取得するには、場所

last_placeラベルを設定しました

私はlast_placeに場所のラベルを取得します。

同じルートに2回同じ場所がある場合はループを作成できますが、私はそれらを防ぐためにリストを作成したいと思いますが、今は私のカメが終わり。

答えて

1

あなたのコードをもっと見ることなく、言いにくい - カメが何をしているのかを知ることは難しいです。コードが機密扱いの場合は、再現可能な例を作成するためにMCVE guidelinesのヒントに従うことをお勧めします。正確な問題に対応する方が簡単かもしれません。

代わりに、ラベルを使用する代わりに、カメに「場所」のカメやパッチをタートル変数に格納させるほうがよいでしょう。この単純な例の設定を使用:

breed [ walkers walker ] 
breed [ locations location ] 

walkers-own [ location-list ] 

to setup 
    ca 
    create-walkers 10 [ 
    setxy random-pxcor random-pycor 
    set location-list [] 
    pd 
    ] 
    create-locations 20 [ 
    set size 1.5 
    set shape "house" 
    setxy random-pxcor random-pycor 
    ] 
    reset-ticks 
end 

あなたは亀は、彼らがリストに訪れる場所を保存し、それらをそのように参照することができます。

to go 
    ask walkers [ 

    ; Build an agrentset of locations that do not belong 
    ; to each turtle's 'location-list' 
    let unvisited-locations locations with [ 
     not member? self [location-list] of myself 
    ] 

    ; Target the nearest unvisited location 
    let target min-one-of unvisited-locations [ distance myself ] 

    ; if the target exists, move towards it 
    if target != nobody [ 
     face target 
     ifelse distance target > 1 [ 
     fd 1 
     ] [ 
     move-to target 
     set location-list lput target location-list 
     ] 
    ] 

    ; if a turtle visits all locations, remove the 
    ; first location visited from the 'location-list' 
    ; so that it will follow the same pattern continuously 
    if length location-list = count locations [ 
     set location-list but-first location-list 
    ] 
    ] 
    tick 
end 
+0

ウォークの方にする 尋ねる-シービス を[待ち時間> 0 ifelse] – segev

関連する問題