2014-04-30 68 views
0

我正在爲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的形成。

難道你們都可以幫我嗎?我會永遠感謝!

回答

2

你可能一次性編寫一個大型程序,試圖一次學習太多。

從寫一個非常小的程序開始;讓它工作;試圖對其做出微小的改進,並使其發揮作用;等等。如果在任何時候你卡住了,來這裏,顯示你的代碼至多有一個事情打破了它,並要求一個問題特別是你目前停留在一個問題。這是獲得幫助的最有效方法。

一些隨機編碼提示:

這不是有效的代碼:

setxy pxcor = halfedge pycor = halfedge 

setxy預計兩個數字,但你傳遞兩個布爾:pxcor = halfedge是真的還是假的,pycor = halfedge是真的還是假的。我想你可能只是setxy halfedge halfedge

agents with [self != myself]可以簡單地用other agents來代替。