2016-05-26 22 views
0

プログラムの考え方:ウォッチドッグ、羊、オオカミがあります。私の羊はフォードにあり、オオカミは外部から来ています。フォードに入ると、ウォッチドッグが動き始めます。オオカミは羊を食べ、羊は草を食べ、ウォッチドッグはオオカミを怖がらせるべきです(まだ実装されていません)。複数のカメを同時に移動させる

私の問題:すべてのカメは一度に1つずつ動いています。

私が欲しいもの:私は彼らがすべてのティックごとにすべてを一度に動かしたいと思っています。

コード

breed [sheeps sheep] 
breed [wolves wolf] 
breed [watchdogs watchdog] 

turtles-own [attacked?] 

globals [counter 
    attack 
    sheep-energy 
    wolf-energy 
    grass-counter 
    lifespan 
    age 
    num-attacks 
    death-countdown] 

to set-variables-shapes 
    set lifespan 365 * 10 
    set-default-shape sheeps "sheep" 
    set-default-shape watchdogs "dog" 
    set-default-shape wolves "wolf" 
    set sheep-energy 200 
    set wolf-energy 400 
    set death-countdown 60 
end 

to setup 
    clear-all 
set-variables-shapes 
create-fold 
spawn-animals 
    reset-ticks 

end 

to go 

    ask turtles [ 
    move 
    ] 
    respawn-grass 

    ask sheeps [ 
    if (pcolor != green or pcolor != brown) [ 
     move-to one-of patches with [ pcolor = green or pcolor = brown] ;; If i change this with turn-around (procedure), all sheeps die at once. 
    ] 
    eat-grass 
    reproduce 
    sheep-status 
    death 
show sheep-energy 
    ] 

    ask wolves [ 
    attack-sheep 
    if (xcor < 5 and xcor > -14 and ycor < 15 and ycor > -5) [ 

     ask watchdogs [ 
    move 
    if (pcolor != green or pcolor != brown) [ 
     move-to one-of patches with [ pcolor = green] 
    ] 
     ] 
    ] 
    ] 

tick 
end 

to create-fold 
    ask patches [ 
    if (pxcor < 6 and pxcor > -15 and pycor < 16 and pycor > -6)[ 
     set pcolor grey] 
    if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5) [ 
     set pcolor green] 
    ] 

end 


to sheep-status 
    if (pcolor = brown) [ 
    set sheep-energy sheep-energy - (life-from-food/2)] 
    if attacked? 
    [set color red] 

end 


to attack-sheep 
    ask other sheeps in-radius (size)[ 
     set attacked? true 
     set color red 
    ] 

end 
to reproduce 
    if (age = lifespan/10) [ 
    hatch-sheeps 40 [ 
     hatch-options 
     ] 
    ] 
end 

to eat-grass 
    if (pcolor = green)[ 
    set pcolor brown 
    set sheep-energy sheep-energy + life-from-food 
    ] 
end 

to respawn-grass 
    ask patches [ 
    if pcolor = brown [ 
    ifelse grass-counter = 0 [ 
     set pcolor green 
     set grass-counter grass-respawn-timer 
    ] 
    [ set grass-counter grass-counter - 1] 
    ] 
    ] 
    end 
to death 
    sheep-death-timer 
    if (sheep-energy <= 0) 
    [die] 
    ;;if (age >= lifespan) [die] 
    sheep-explode 

end 

to sheep-death-timer 
    if (attacked?)[ 
    set death-countdown death-countdown - 1 

    if (death-countdown <= 30) 
    [set color black] 
    if (death-countdown <= 0) 
    [die] 
    ] 
end 

to sheep-explode 
    if (sheep-energy >= 10000)[ 
    hatch-sheeps 20 [ 
    hatch-options] 
    die 
    ] 
end 

to hatch-options 
    set sheep-energy 200 
     set age 1 
     set attacked? false 
    end 

to move 
    fd 1 
    rt random 90 
    lt random 90 
end 

to spawn-animals 
    create-wolves number-of-wolves [ 
     set color red 
     setxy 10 -10 
     set size 1.3 
     ask patch 10 -10[ 
     Set plabel "Wolves"] 
    ] 
    create-sheeps number-of-sheeps [ 
    if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5)[ 
     setxy -4.5 5] 
    ask patch -4.5 15 [ 
     Set plabel "Sheeps"] 
    set color white 
    set attacked? false 
    ] 
create-watchdogs number-of-dogs [ 
    if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5)[ 
    setxy -4.5 5 
    set size 1.3] 
    set color blue 
    ] 
end 
to turn-around 
    fd -1 
    rt 180 
end 
+1

あなたは早期羊の死亡について別途質問する必要があります。 –

答えて

0

NetLogoには「同時に」というものはありません。 NetLogoはシングルスレッドであり、並列処理をサポートしていません。

すべてのエージェントが同じティック中に移動した場合、すべてのエージェントがティックの過程で発生したため、「同時に」と考えることができます。

しかし、1回のティックでは、文字通りエージェントが一度に1つずつ移動する方法はありません。

+0

ありがとう! NetLogoについてもっと学ぶために管理され、私は結局それが不可能であると理解した。 :) –

-1

あなたは同時に各羊のエージェントはすべての動きを作るために

ask-concurrent sheeps [move ] 

を使用することができますが、それは問題ではないはず、彼らは実際にはお勧めしません。あなたはそれを使用します。

+1

'ask-concurrent'はそれをしません。エージェントはまだ一度に1つずつ移動します。 ( 'ask-concurrent'が実際に何をしているのかを説明するのは非常に難しいので、私たちが決してそれを勧めない理由の一部です) –

関連する問題