我想设置一个规则的海龟网格。在下面的例子中,我已经在x维度上分配了相等间隔的阅读器代理,但是我不能设置每行代理的最大数量,并在世界上放置以下读者行。
breed [readers reader]
globals [ reader-ycor ]
to setup
clear-all
setup-globals
setup-readers
end
to setup-globals
set-default-shape readers "square 2"
set reader-ycor (min-pycor + 1)
end
to setup-readers
let horizontal-interval (world-width / number-of-readers)
create-readers number-of-readers [
set color green
setxy (min-pxcor - 0.5 + horizontal-interval * (0.5 + who)) reader-ycor
set size 3
set label ""
]
end
to go
setup
end
全局number-of-readers
表示readers
的总数,max-number-per-row
表示变量设置为10(每行的最大读者数)。
我不知道当一行有10个读者时如何告诉x坐标停止,以及当读者的who
大于10时如何告诉Netlogo添加新的读者行。 / p>
此致
答案 0 :(得分:2)
我认为不是使用who
数字(不推荐使用),而是手动计算坐标然后在计算值上产生海龟可能会更好。使用此设置:
breed [ readers reader ]
to setup
ca
spawn-by-row
reset-ticks
end
这些读者每行和读者数量的滑块:
此代码将根据最低x / y值(注释中的详细信息)构建读者:
to spawn-by-row
; get the intervals
let h-int world-width / readers-per-row
let v-int world-height / readers-per-row
; Get a range of horizontal and vertical coordinates, starting at half
; of the interval value from the minimum x coordinate
let h-vals ( range ( min-pxcor + h-int / 2 ) max-pxcor h-int )
let v-vals ( range ( min-pycor + v-int / 2 ) max-pycor v-int )
; Create an empty list to build into
let possible-coords []
; For each possible vertical value, map all horizontal values in order and
; combine these into an ordered list starting at the lowest px and py coords
foreach v-vals [
v ->
set possible-coords ( sentence possible-coords map [ i -> (list i v) ] h-vals )
]
; Use the number of readers to sublist the possible coordinates, and
; create a turtle at each of the coordinate combinations left.
let use-coords sublist possible-coords 0 number-of-readers
foreach use-coords [
coords ->
create-readers 1 [
setxy item 0 coords item 1 coords
set shape "square 2"
]
]
end
如果您number-of-readers
的{{1}}多于readers-per-row
,则会产生错误,但这很容易解决。
编辑2:
将distance-var
的滑块添加到上面的界面,然后尝试spawn-by-row
to spawn-by-row
; Get a range of coordinate values
let half-step 0.5 * distance-var
let d-vals ( range ( min-pxcor + half-step ) ( max-pxcor ) distance-var )
; Create an empty list to build into
let possible-coords []
; For each possible vertical value, map all horizontal values in order and
; combine these into an ordered list starting at the lowest px and py coords
foreach d-vals [
d ->
set possible-coords ( sentence possible-coords map [ i -> (list i d) ] d-vals )
]
; Use the number of readers to sublist the possible coordinates, and
; create a turtle at each of the coordinate combinations left.
let max-positions length possible-coords
if max-positions > number-of-readers [ set max-positions number-of-readers ]
let use-coords sublist possible-coords 0 max-positions
foreach use-coords [
coords ->
create-readers 1 [
setxy item 0 coords item 1 coords
set shape "dot"
set color white
]
]
end
答案 1 :(得分:0)
我已经管理了一个解决方案,但使用了可避免的who
数字。
breed [readers reader]
undirected-link-breed [ rris rri ]
globals [ reader-ycor ]
to setup
clear-all
ask patches [ set pcolor blue - 3 ]
setup-globals
setup-readers
end
to setup-globals
set-default-shape readers "square 2"
set separation-distance-ratio 10 ; should be > 10
set number-of-readers 24
set interf-rri-radius 110
end
to setup-readers
let horizontal-interval (world-width / separation-distance-ratio )
let vertical-interval (world-height / separation-distance-ratio )
create-readers number-of-readers [
setxy (min-pxcor - 0.5 + horizontal-interval * (0.5 + who mod 10 ))
(min-pycor - 0.5 + vertical-interval * (0.5 + floor (who / 10) ) )
set size 2.5
set color green
]
ask readers [ create-rris-with other readers in-radius interf-rri-radius ]
end
to go
setup
end