2017-09-20 1 views
1

亀を動かすのをやめようとしているのは、patch-ahead 1 conditionです。それは、次の隣接パッチで特定の性質を持つ別のカメ、実際には が見つかった場合には、私は固定カメに達すると、互いに隣接するカメを止めたい。亀が止まる前にパッチアウェイ条件が働かない

ifelse (not any? (turtles-on patch-ahead 1) with [stationary? = true]) [ 
    fd 0.1 
    rt random 360 
] [ 
    set stationary? true 
    stop 
] 

は実際に、私は「import-pcolors」コマンドを使用してインポートを描く中で、私のカメを停止させるためのパッチ先読み1つの条件を使用しています。

世界の斑点の中央には図形や形(星形魚など)が並んでいて、終わりまで固定された形状描写内に4匹のカメ(種子)が原点の中心近くに配置され、他のすべての亀無作為に配置され、無作為に移動します。stationary? = false

目的は、亀をランダムに移動させて次の固定カメに近づくと停止し、stationary? = trueになり、他の残りの非定常の参照を完全に埋めることですカメ。ここ

は、私がこれまで試してみました、私が達成したい

to setup 
     import-pcolors "starnew.png" ; image imported in the world on patches for turtles to interact 

     create-robots num-of-robots 
     [ 
      set seed? false 
      set stationary? false 
     set shape "circle 2" 
     setxy random-pxcor random-pycor 
     ] 

     ask turtles 
     [ 
     if who = 0 ; similarly for who = 1 (setxy = 0 1), who = 2 (setxy = 1 0), who = 3 (setxy = 0 -1), having loaction near centre origin 
     [ 
      setxy 0 0 
      set seed? true 
      set stationary? true 
      set localized? true 
      ] 
     ] 
    end 
    to go 
ask robots with [stationary? != true] 
    [ 

    ifelse pcolor = white ;; out-shape 
     [ 
     wall 
     fd 0.1 
     rt random 30 
     lt random 30 
     ] 
     [      ;; In-shape 
     set pos-inside? true 
     ifelse (not any? (robots-on patch-ahead 1) with [stationary? = true or seed? = true] ) 
     [ 
      fd 0.1 
      rt random 30 
      lt random 30 
     ] 
     [ 
      set pos-inside? true 
      set stationary? true 
      set localized? true 
      stop 
     ] 
     ] 
    ] 
    end 

望ましい行動を下図に示したものです。 enter image description here

答えて

2

セットアップコードを見ずに確かに言うのは難しい(MCVE guidelinesを参照)が、私はtrueにstationaryセットで出始めて、あなたのカメは、すべてのfalseに等しいstationary?で出始めていると何のカメが存在しないと思われます(あなたのコードをいくつかの固定カメで走らせると、それは私が知る限りで動作します。少し修正したバージョンを試して、それがあなたの後ろに近づくかどうかを確認してください:

turtles-own [ stationary? ] 

to setup 
    ca 
    crt 50 [ 
    setxy random-pxcor random-pycor 
    set stationary? false 
    ] 
    ask n-of 15 turtles [ 
    set stationary? true 
    ] 
    reset-ticks 
end 

to go 
    ask turtles with [ stationary? = false ] [ 
    ifelse (not any? (turtles-on patch-ahead 1) with [stationary? = true]) [ 
     fd 0.1 
     rt random 360 
    ] [ 
     print "Found a stationary turtle. I'll be stationary too." 
     set stationary? true 
    ] 
    ] 
    tick 
end 
+0

ルークC、あなたの親切な助けをありがとう。 あなたはそれを得ました。 –

+0

しかし私は私のシナリオを明らかにする。 –

関連する問題