Netlogo - 导入表示边 2^n 的矩阵的 CSV 并设置补丁的值

Netlogo - importing a CSV representing a matrix of side 2^n and setting the value of patches

我的模型适用于始终是边长为 2^N 的正方形的世界。

我想要一些代码可以让我像这样导入 CSV:

3
5; 6; 8; 9; 8; 4; 1; 5
7; 7; 8; 2; 9; 5; 2; 6
5; 8; 4; 2; 6; 8; 9; 2
5; 4; 9; 8; 6; 3; 2; 4 
5; 6; 8; 9; 8; 4; 1; 5
7; 7; 8; 2; 9; 5; 2; 6
5; 8; 4; 2; 6; 8; 9; 2
5; 4; 9; 8; 6; 3; 2; 4

值 3 代表 N,因此世界大小应设置为 8 x 8 块 (2^3=8) 的正方形。

补丁拥有一个名为 "value" 的变量,我想根据 CSV 中的值设置这些值。

正如 Seth 所提到的,CSV 扩展可以在此处提供帮助:

let matrix but-first (csv:from-file "filename.csv" ";") ; `but-first` since we don't care about that first line

ask patches [
  let row max-pycor - pycor
  let column pxcor - min-pxcor
  set value item column item row matrix
]