0
創建重疊的代理商使用下面的代碼,我得到的代理商是這樣的: 在一條線上
to setup
ask breadth-patches [sprout-walls wall-agents[set color 2]]
ask length-patches [sprout-walls wall-agents[set color 2]]
ask gap-patches [sprout-walls wall-agents[set color 2]]
ask length-patches[align-inside-at-top]
ask breadth-patches [align-inside-at-right-left]
ask gap-patches[align-inside-at-top]
end
to align-inside-at-top ;; patch procedure
let counter count walls-here ;; we will use this as a count-down, after using it in some calculations
if counter > 0 ;; could assume there are turtles, but we are not.
[ let gap1 1/counter ;; size of turtles, gap between turtles
let half-gap gap1/2 ;; half-size of turtles
let ytop 0
if-else(pycor < 0)[set ytop pycor - .5 - half-gap]
[set ytop pycor + .5 - half-gap]
let xleft pxcor - .5 - half-gap
ask walls-here
[ set size gap1
set ycor ytop
set xcor xleft + gap1 * counter
set counter counter - 1 ;; so we're placing them from right to left
; set ycor ycor + 0.125
]
]
end
to align-inside-at-right-left ;; patch procedure
let counter count turtles-here ;; we will use this as a count-down, after using it in some calculations
if counter > 0 ;; could assume there are turtles, but we are not.
[ let gap1 1/counter ;; size of turtles, gap between turtles
let half-gap gap1/2 ;; half-size of turtles
let ytop pycor + .5 + half-gap
let xleft 0
if-else (pxcor < 0)[
set xleft pxcor + .5 - half-gap]
[ set xleft pxcor - .5 + half-gap
]
ask turtles-here
[ set size gap1
set ycor ytop - gap1 * counter
set xcor xleft ;+ gap * counter
set counter counter - 1 ;; so we're placing them from right to left
]
]
end
注:在矩形的差距是由於下面的代碼
ask patches with [pxcor > (gap * (-1)) and pxcor < gap and pycor =(breadthrec - 1)][ask walls-here[die]]
這裏,gap = 1,即1個補丁的寬度。
所以輸入參數是wall-agents
,它指定了沿長度和寬度補丁程序爲每個補丁創建的代理程序數量。 我希望更改爲創建重疊代理(如下圖所示)(對不起,該圖不太完美,但我希望它可以解釋它)。請幫助如何做到這一點。
謝謝!這很有見地。我明白所說的是什麼,但我的確這麼做,因爲在這種情況下簡單地在一個補丁上解決它很簡單。由於間隙補丁和矩形尺寸限制,這個問題需要解決。 –
好的,但是你的問題並不清楚。你能更具體地說明你有什麼困難嗎?你究竟在哪裏陷入困境?如果缺口部分很難,那麼可能會問一個關於缺口部分的問題。如果處理角落很困難,也許會問一個關於角落的問題。這是一堆複雜的代碼,我必須研究它30分鐘,以便全面瞭解它並真正理解它,以及如何改進它。幾乎沒有人有30分鐘的時間,所以如果你需要幫助,你肯定會找到更具體的問題。 –
謝謝!你是對的,我應該調試得更多,更具體。我現在用很長很長的路解決了它。將嘗試修改該問題以尋找更好的解決方案。 –