2017-11-24 5 views
1

私はカメを狩りに出すようにコーディングしましたが、獲物を見つけたときには単に食べていますが、代わりに成功のチャンスを数学的要素で入力するのですか?ハント成功netlogo

本質的に獲物を見つけたら、サイコロを振って、食べることができるかどうかを確認してください。

to search ;when wolf is hungry 
    set energy energy - 1 
    fd v-wolf 
    if random 600 = 1 ;; frequency of turn 
    [ ifelse random 2 = 0 ;; 50:50 chance of left or right 
    [ rt 15 ] ;; could add some variation to this with random-normal 45 5 
    [ lt 15 ]] ;; so that it samples from a dist with mean 45 SD 5 

    ;; check if it can see a prey/food item 
    ;; here i think we probably pick one of several possible prey 
    ;; that are detectable randomly using the one-of command. 
    ;; We should probably select the nearest one instead, but 
    ;; i cant code that off the top of my head 
    if any? prey in-radius smell [set heading towards one-of prey in-radius smell] 
    if energy < 0 [die] 

end 


To eat ;to kill prey and eat it 
    let kill one-of prey-here in-radius smell 
    ;move-to (need to code it so they move toward prey in a radius 
    ;need to code in a variable for success too 
    if kill != nobody 
    [ask kill [ die ] 
     set energy energy + 10000] 
end 

答えて

3

はい、乱数を生成し、その乱数が特定の条件を満たす場合にのみ、killコマンドを実行できます。通常の方法は、0と1の間の乱数(NetLogoではrandom-float 1)を生成してから、例えば40%の確率が必要な場合はif random-float 1 < 0.4 [ <what happens> ]のようにします。コメントに反応して

to eat 
    let kill one-of prey-here in-radius smell 
    if kill != nobody and random-float 1 < 0.4 
    [ ask kill [ die ] 
    set energy energy + 10000 ] 
end 

これが何をしているかを理解しようとする試みを行い、最初の答えについてあなた自身を考えてください。どんなコマンドが何を意味しているのか、それとも何らかのコマンドのシーケンスが何であるのかを理解していないなら、あなたがするまで動かないでください。コードが簡単な間に学習しなければ、構築しているモデルで行う必要のあるより難しいことを決して解くことはできません。それは、ここに獲物一の殺しましょう 獲物殺すようにと食べにおける半径香り ;

+0

食べること!殺すならば、成功のための変数内のコードへの必要性があまりにも =誰も は[[ダイ] 殺すお願いしますエネルギーエネルギーを10000に設定] end これは私の狩りのコマンドです。ランダムフロートコマンドはどこに追加しますか? –