Tag: conways game of life

康威的生命游戏:更改邻居计数function后,单元格更改计算错误

想知道是否有人可以帮助我解决这个小问题。 我写了一个函数来计算康威生命游戏中一个细胞的活着的邻居: int countLivingNeighbours(int a[][GRID_WIDTH], int x, int y){ int count = 0, cx, cy; for(cy = y – 1; cy <= y + 1; cy++){ for(cx = x – 1; cx <= x + 1; cx++){ if(a[cy][cx] == ALIVE){ count++; } } } // subtract 1 so it's not counting it's own cell count–; […]

(生命游戏)如何循环遍历矩阵的外层而不检查它的外部,同时检查邻居?

矩阵中的每个点代表一个生命或死亡的细胞。 我必须计算每个单元格中有多少个ALIVE邻居。 我有一个function,但它检查边界外的单元格。我不知道如何在不执行大量if-else语句的情况下同时检查邻居并跟踪边缘。 void Neighbours(int rows, int cols, cell world[rows][cols], int neighbors[rows][cols]) { //Loop through each cell in the matrix. for(int rCell = 0; rCell < rows; rCell++){ for(int cCell = 0; cCell < cols; cCell++) { //Reset neighbor count for each cell. neighbors[rCell][cCell] = 0; //Check cell status in cell's vicinity of each cell. […]