2016-10-23 5 views
2

임의로 움직이는 특정 장애물을 피하면서 간단한 시뮬레이션 시뮬레이션을 만들려고합니다. 나는 그들이 그곳에 갔던 장소의 좌표를 저장하기를 원하기 때문에 다시는 가지 않습니다. 이것은 내가 지금까지 가지고있는 것의 일부입니다 :NetLogo의 목록에 에이전트 좌표 저장

to move-agent 

    let move random 3 
    if (move = 0) [] 
    if (move = 1)[ left-turn ] 
    if (move = 2)[ right-turn ] 

    set xint int xcor ;;here i'm storing the coordinates as integers 
    set yint int ycor 

    set xylist (xint) (yint) 

    go-forward 

end 

to xy_list 
    set xy_list [] 
    set xy_list fput 0 xy_list ;;populating new list with 0 
end 

그러나 "SET expected 2 inputs"오류가 계속 발생합니다. 아무도 이것으로 나를 도울 수 있습니까?

답변

3

xy_list을 변수 및 거북 변수로 잘못 사용하고있는 것 같습니다.

xy_list 프로 시저가 필요하지 않습니다. 거북이 변수로 유지하십시오. 확인 xy_list은 거북이 - 자신의 목록에 : 당신이 거북이를 만들 때

turtles-own [xy_list]

빈 목록으로 초기화합니다. 예를 들면 : 당신은 그 이미 존재 좌표 있는지 확인해야합니다

set xy_list fput (list int xcor int ycor) xy_list 

:

crt 1 [set xy_list []]

거북이 이동, 당신은 xcor으로 자신의 현재 위치를 추가 할 수 있습니다, ycor 목록 목록으로 이동하기 전에.

그러나 정수 좌표를 사용하면 거북이의 기록을 추적하기 위해 패치 세트를 사용하는 것이 훨씬 쉬울 것입니다. 시도해 볼 수 있습니다 :

turtles-own [history] 

to setup 
    ca 
    crt 3 [set history (patch-set patch-here) pd] 
end 

to go 
    ask turtles [ 
    let candidates neighbors with [not member? self [history] of myself] 
    ifelse any? candidates 
     [move-to one-of candidates stamp 
     set history (patch-set history patch-here)] 
     [die] 
    ] 
end