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分钟的时间,所以如果你需要帮助,你肯定会找到更具体的问题。 –
谢谢!你是对的,我应该调试得更多,更具体。我现在用很长很长的路解决了它。将尝试修改该问题以寻找更好的解决方案。 –