我正在爲Netlogo和我的大學完成這項任務,而且我很困難。 我剛開始使用Netlogo,我正試圖與一些朝聖者一起重新創建Mekka。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
- 的想法是首先,一個正方形被設置爲類似於kaaba。
- 之後,烏龜成立。
- 他們應該都是逆時針方向繞着牆壁走動。
- 應該有一個'領導',這將導致周圍的朝聖者朝聖者。
現在kaaba被成功繪製出來,唯一的問題是海龜不應該在那裏產卵或碰到它(因此凹凸代碼)。另外,他們隨機四處走動,我不知道如何讓他們沿着一個不同顏色的領導者進行反向Clickwise的形成。
難道你們都可以幫我嗎?我會永遠感謝!