2017-11-24 2 views
1

나는 내 거북이를 외우고 사냥을했는데, 먹이를 발견했을 때 먹는다고했을 때, 성공의 기회 대신 수학적 요소를 덧붙여서 항상 100 %사냥 성공 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

예, 임의의 숫자를 생성 한 다음 임의의 숫자가 특정 조건을 충족하는 경우에만 강제 종료 명령을 수행 할 수 있습니다. 일반적인 방법은 (NetLogo에서 random-float 1입니다) 당신은 예를 들어 40 %의 확률을 원하는 경우 다음 if random-float 1 < 0.4 [ <what happens> ] 그런 짓을 0과 1 사이의 임의의 숫자를 생성하는 것입니다. 응답에서

는 언급합니다 :

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] 끝 이 사냥 나의 명령입니다. 무작위 부동 명령을 어디에 추가해야합니까? –