稍微参与下,呵呵, 我贴下我的关键算法, 很菜, 转成批处理速度应该很慢吧- for (i = 0; i < N; ++i)
- for (j = 0; j < N; ++j) {
- sum = list[(i+1+N)%N][(j+N)%N] + list[(i-1+N)%N][(j+N)%N] + list[(i+N)%N][(j+1+N)%N] + list[(i+N)%N][(j-1+N)%N];
- sum += list[(i+1+N)%N][(j+1+N)%N] + list[(i+1+N)%N][(j-1+N)%N] + list[(i-1+N)%N][(j-1+N)%N] + list[(i-1+N)%N][(j+1+N)%N];
- switch (sum) {
- case 2://不变
- backUp[i][j] = list[i][j]; break;
- case 3://生
- backUp[i][j] = 1; break;
- default://死
- backUp[i][j] = 0; break;
- }
- }
- for (i = 0; i < N; ++i)
- for (j = 0; j < N; ++j)
- list[i][j] = backUp[i][j];
复制代码
|