내 영어 : 그것에 대해 명확하고 죄송 만든 희망하지만, 다음과 같은 품종이 가정 :
breed [ obstacles obstacle ]
breed [ nodes node ]
당신은 사용할 수 있습니다 다음 기자 :
to-report can-see? [ target ]
let result false
hatch 1 [
face target
fd 0.1
set result ifelse-value (any? turtles-here with [ self = target ])
[ true ]
[ ifelse-value (any? obstacles-here)
[ false ]
[ can-see? target ]
]
die
]
report result
end
는 hatch
대상의 방향으로 임시 노드의 전체 시리즈를 보내고 방식으로 작동합니다. 도중에 어떤 노드가 장애물을 만나면 false
을 반환합니다. 목표에 도달하면 true
을 반환합니다. 이러한 임시 노드는 결과가 얻어 질 때까지 재귀 적으로 생성됩니다.
"단계 크기"(이 예에서는 fd 0.1
)를 조정할 수 있습니다.이 단계 크기가 클수록 장애물 모서리가 빠져 나올 확률이 높지만 속도는 약간 빠릅니다.
또한 tick based updates instead of continuous updates을 사용하고 있는지 확인해야합니다. 그렇지 않으면 매우 느립니다.
to setup
ca
ask n-of 100 patches [
sprout-obstacles 1 [
set color red
set shape "square"
]
]
ask n-of 50 patches with [ not any? obstacles-here ] [
sprout-nodes 1 [
set color yellow
set shape "circle"
let targets other nodes
create-links-with targets with [ can-see? myself ]
]
]
end
당신이 장애물로 패치 대신 거북이를 사용하려면
, 당신은 아마 상당히 쉽게 수정할 수 있습니다 여기에
는 서로를 볼 수있는 노드 사이의 링크를 생성하는 예이다.