我正在使用2D数组来计算其邻居并在给定其邻居计数的情况下更新当前单元格。我的计数方法(lifeCount = countAlive(copy,i,k))正在查看更新的数组而不是原始数组。我需要它继续查看原始而不是副本。如果有人能提供帮助我会很感激。
public static void UpdateMatrix(boolean original[][]) {
int lifeCount;
boolean[][] copy = (boolean[][]) original.clone(); //copy array
for (int i = 1; i < original.length - 1; i++) {
for (int k = 1; k < original[i].length - 1; k++) {
lifeCount= countAlive(copy,i,k);
System.out.println(lifeCount);
if (original[i][k] == true) {
if (lifeCount < 3 || lifeCount > 8) {
copy[i][k] = false;
}
}
if (original[i][k] == false) {
if (lifeCount >= 3 && lifeCount <= 8) {
copy[i][k] = true;
}
}
} /// matrix has updated
}
}// end findNeighborg