私は Netlogo を使用して大学のこの課題に取り組んでいますが、本当に行き詰っています。Netlogo を使い始めたばかりで、巡礼者と一緒に Mekka を再現しようとしています。
私は多くの異なるコードを試し、新しいコードを追加したり、試したり、いくつかを削除したりしてきましたが、これが私がこれまでに思いついたものです:
turtles-own
[direction ;; 1 follows right-hand wall, -1 follows left-hand wall
way-is-clear? ;; reporter - true if no wall ahead
checked-following-wall?]
globals [halfedge]
breed [agents agent ]
agents-own [ around visible ]
to setup
create-agents 500 [
set color green
set size 2
; distribute agents randomly
setxy pxcor = halfedge pycor = halfedge
set heading random 360
; ensure that each is on its own patch
while [any? other agents-here] [ fd 1 ]
]
end
to bounce
if [pcolor] of patch-at dx 0 = blue [
set heading (- heading)
]
if [pcolor] of patch-at 0 dy = blue [
set heading (180 - heading)
]
end
to go
ask agents [ count-those-around ]
ask agents [ move ]
end
; store the number of agents surrounding me within
; local-radius units
; and the agents that I can see within visible-radius
to count-those-around
set around count agents with [self != myself] in-radius
local-radius
set visible agents with [self != myself] in-radius
visible-radius
end
to move
;; turn right if necessary
if not wall? (90 * direction) and wall? (135 * direction) [ rt 90 * direction ]
;; turn left if necessary (sometimes more than once)
while [wall? 0] [ lt 90 * direction ]
;; move forward
fd 1
end
; face towards the most popular local spot
to face-towards
face max-one-of visible [around]
end
; face away from the most popular local spot
to face-away
set heading towards max-one-of visible [around] - 180
end
to setup-center
clear-all
set halfedge int (edge / 2)
ask patches[
if (pxcor = (- halfedge) and pycor >= (- halfedge) and pycor <= (0 + halfedge) )
[set pcolor blue] ;; ... draws left edge in blue
if ( pxcor = (0 + halfedge) and pycor >= (- halfedge) and pycor <= (0 + halfedge) )
[set pcolor blue] ;; ... draws right edge in blue
if ( pycor = (- halfedge) and pxcor >= (- halfedge) and pxcor <= (0 + halfedge) )
[set pcolor blue] ;; ... draws bottom edge in blue
if ( pycor = (0 + halfedge) and pxcor >= (- halfedge) and pxcor <= (0 + halfedge) )
[set pcolor blue] ;; ... draws upper edge in blue
]
end
- アイデアは、最初に、カーバ神殿に似た正方形が設定されるということです。
- その後、カメがセットアップされます。
- 彼らは皆、反時計回りに壁の周りを歩くことになっています。
- カーバ神殿周辺のすべての巡礼者を導く 1 人の「リーダー」がいるはずです。
現在、カーバ神殿は正常に描画されていますが、唯一の問題は、カメがそこにスポーンしたり、そこに遭遇したりしないことです (したがって、バンプ コード)。また、それらはランダムに回っていて、色の異なる 1 つのリーダーに続いて、カウンター クリック フォーメーションで移動させる方法がわかりません。
どなたか助けていただけませんか?私は永遠に感謝します!