2014-03-05 5 views
0

저는 Netlogo와 stackoverflow를 처음 접했지만 다른 게시물은 이미 저에게 많은 도움이되었습니다.거북이 서로 마주 보는 방법, 3 tick을 기다린 후 방황하고 계십니까?

저는 현재 에이전트가 임의로 공간을 돌아 다니며 만날 때마다 멈추게하는 모델을 프로그램하려고합니다. 여기에서 "만남"은 "서로를 지나친다"는 의미입니다. in-radius 2. 그들은 각각 face이어야하며, 2 tick을 기다린 후 다음 상담원을 찾을 때까지 계속 움직여야합니다.

NzHelen's question on a timer을 사용해 보았지만 실제로 성공하지 못했습니다.

지금까지 나는 서로 마주 할 수있었습니다. 내 코드의 올바른 위치에 tick- 명령을 넣는 데 문제가 있습니다. (편집 : 이것은 세스 덕분에 wait- 명령을 내림으로써 해결되었습니다. -> 나는 모든 거북이가 움직이지 않고 서로 만나는 것을 좋아합니다.) 내가 노력하고있는 또 다른 한 가지는 예를 들어 만나는 시간에 패치가 깜박이거나 만날 때 주변에 나타나는 서클 등 모임의 시각적 표현 일종입니다. wait- 명령을 사용하면 모든 것이 다시 중지되므로 방지하고 싶습니다.

아래 코드는 다음과 같습니다.

to go 

    tick 

    ask turtles 
    [ 
    wander 
    find-neighbourhood 
    ] 

ask turtles with [found-neighbour = "yes"] 
    [ 
    face-each-other 
    ] 

ask turtles with [found-neighbour = "no" or found-neighbour = "unknown"] 
[ wander ] 

    end 

;------- 
;Go commands  

to wander 
     right random 50 
     left random 50 
     forward 1 
end 

to find-neighbourhood 
    set neighbourhood other turtles in-radius 2 
    if neighbourhood != nobody [wander] 
    find-nearest-neighbour 
    end 

    to find-nearest-neighbour 
    set nearest-neighbour one-of neighbourhood with-min [distance myself] 
    ifelse nearest-neighbour != nobody [set found-neighbour "yes"][set found-neighbour "no"] 
      end 

to face-each-other        ;;neighbour-procedure 
    face nearest-neighbour 
    set found-neighbour "no" 
    ask patch-here [        ;; patch-procedure 
    set pcolor red + 2 
    ;wait 0.2 
    set pcolor grey + 2 
     ] 
    if nearest-neighbour != nobody [wander] 
    rt 180 
    jump 2 

    ask nearest-neighbour 
[ 
    face myself 
    rt 180 
    jump 2 
    set found-neighbour "no" 
    ] 
    end 
+0

주석이 달린 코드가 많아 들여 쓰기가 힘들 때 코드를 읽는 것이 정말 어렵습니다. 그 이유는 누구도이 질문에 답하지 않으려 고하는 이유 일 수 있습니다. 읽기 쉽고 쉬운 코드가 아닙니다. –

+0

나에게 뛰어 오는 한 가지 점은 당신이 분명히 '대기'를 사용하고 싶지 않다는 것이다. 어느 거북이조차도 '기다리는'동안 모든 것이 멈 춥니 다. –

+0

두 가지 모두 매우 유용한 설명입니다. 감사합니다. 그에 따라 편집하려고합니다. –

답변

1

동료의 도움을 받아 필자는 타이머 문제를 해결할 수있었습니다. Seth가 지적한 것처럼 wait은 올바른 명령이 아니며 너무 많은 to-end -loops가 내 거북이를 혼란스럽게 만들었습니다. 코드는 이제 다음과 같이 보이며 작동합니다. 거북이가 서로 가까워지고 서로 마주 보며 별 모양으로 변하고 3 개의 진드기를 기다린 다음 반대 방향으로 점프합니다.

to setup 

    clear-all 
ask turtles 
    [ 
    set count-down 3 
    ] 
reset-ticks 

end 
;--------- 
to go 

ask turtles 
    [  
    if occupied = "yes" [ 
    ifelse count-down > 0 
[ 
     set count-down (count-down - 1) 
     set shape "star" 
    ][ 
     set shape "default" 
     rt 180 
     fd 2 
     set occupied "no" 
     set count-down 3 
    ] 
    ] 

    if occupied = "no" [ 
    ; Wandering around, ignoring occupied agents 

    set neighbourhood other turtles in-radius 2 

    ; If someone 'free' is near, communicate! 

    set nearest-neighbour one-of neighbourhood with-min [distance myself] 
    ifelse nearest-neighbour != nobody [ 
     if ([occupied] of nearest-neighbour = "no") [ 
      face nearest-neighbour    
      set occupied "yes" 
      ask nearest-neighbour [ 
       face myself    
       set occupied "yes" 
      ]] 
    ][ 
     ; No one found, keep on wandering 
     wander 
    ]]] 
    tick 
    end 
;------- 
;Go commands  

to wander 
     right random 50 
     left random 50 
     forward 1 
end 
0

당신은 Nzhelen의 질문에 링크 할 수 있습니다. 본질적으로 당신의 질문에 대한 대답은 당신이 똑같은 일을해야한다는 것입니다. 당신이 그것을하려 할 때, 당신은 바른 길을 가고있었습니다. 나는 또 다른 찌르는 것을 제안 할 것이고, 만약에 붙어 있다면, 정확히 어디에서 붙어 있는지 보여주십시오.

+0

동료로부터 도움을 받았으며 문제를 해결할 수있었습니다. 내가 지금 다음 단계에 머 무르지는 않았지만 나는이 질문을 닫을 수 있다고 생각한다. 어떻게 할 수 있는가? –

+0

솔루션이 다른 사람들에게 도움이 될 수 있기 때문에 자신의 질문에 답변하고 코드를 게시 할 수 있습니다. 또는 닫으려면 http://meta.stackexchange.com/questions/37752/how-do-i-close-my-own-question을 참조하십시오. –