对于给定的补丁集(总是一个正方形),我需要找到pxcor和pycor的最大值和最小值,以获得像
这样的列表[0 10 10 0]
代表由点
界定的方格(0,0), (10,0), (0,10), (10,10)
所以我需要我将数据作为输入补丁集并返回一个类似示例中的列表。
答案 0 :(得分:2)
给定一个名为p-set
的补丁集,您可以使用此记者:
to-report get-max-min [p-set]
let coord []
ask one-of p-set with-min [pxcor] [set coord lput pxcor coord]
ask one-of p-set with-max [pxcor] [set coord lput pxcor coord]
ask one-of p-set with-min [pycor] [set coord lput pycor coord]
ask one-of p-set with-max [pycor] [set coord lput pycor coord]
report coord
end
使用范例:
我想用pcolor = red
let coord get-max-min (patches with [pcolor = red])
答案 1 :(得分:2)
我能想到的最简单的方法是:
to-report get-max-min [p-set]
let xs [pxcor] of p-set
let ys [pycor] of p-set
report (list min xs max xs
min ys max ys)
end