把世界分成相等的部分
Divide world into equal parts
已编辑
删除了重复的问题。有关已删除的问题,请参阅 。
2)我想把世界分成9或16个部分(大小相同)。我希望世界是几个正方形(3x3 或 4x4)。我在 Whosebug and with @Bryan Head's code, I can generate something like this 找到了一些正确的东西。但是我不希望大小是随机的,我希望所有区域都具有相同的大小。
; Dividing the world randomly into 14 parts.
ca
let region-num 0
ask n-of 14 patches [
set pcolor item region-num base-colors
set region-num region-num + 1
]
while [ any? patches with [ pcolor = black ] ] [
ask patches with [ pcolor != black ] [
ask neighbors with [ pcolor = black ] [ set pcolor [ pcolor ] of myself ]
]
]
谢谢!
对于第 2 点:您可以使用
ask patches with [pxcor < 3 and pycor < 3]
将所有补丁放在一个角落。您可以在此基础上展开,将地图分成几部分。
编辑以扩展我的评论:试试下面的代码。
to test
resize-world 0 8 0 8
let x 3
let y 3
let col 5
while [y <= 9][
while [x <= 9][
ask patches with [pxcor < x and pxcor >= x - 3 and pycor < y and pycor >= y - 3][
set pcolor col
]
set x x + 3
set col col + 10
]
set x 3
set y y + 3
]
end
已编辑
删除了重复的问题。有关已删除的问题,请参阅
2)我想把世界分成9或16个部分(大小相同)。我希望世界是几个正方形(3x3 或 4x4)。我在 Whosebug and with @Bryan Head's code, I can generate something like this 找到了一些正确的东西。但是我不希望大小是随机的,我希望所有区域都具有相同的大小。
; Dividing the world randomly into 14 parts.
ca
let region-num 0
ask n-of 14 patches [
set pcolor item region-num base-colors
set region-num region-num + 1
]
while [ any? patches with [ pcolor = black ] ] [
ask patches with [ pcolor != black ] [
ask neighbors with [ pcolor = black ] [ set pcolor [ pcolor ] of myself ]
]
]
谢谢!
对于第 2 点:您可以使用
ask patches with [pxcor < 3 and pycor < 3]
将所有补丁放在一个角落。您可以在此基础上展开,将地图分成几部分。
编辑以扩展我的评论:试试下面的代码。
to test
resize-world 0 8 0 8
let x 3
let y 3
let col 5
while [y <= 9][
while [x <= 9][
ask patches with [pxcor < x and pxcor >= x - 3 and pycor < y and pycor >= y - 3][
set pcolor col
]
set x x + 3
set col col + 10
]
set x 3
set y y + 3
]
end