我有一个奇怪的问题,我正在做的运动(生命游戏)。在代码的中间位,行nextgeneration.set(livex,livey,live);导致程序停止运行。有任何想法吗?
int lifeGenerator(Grid<int>& nextgeneration, Grid<int>& birthsanddeaths) {
for (int deadx = 0; deadx < nrows; deadx++) {
for (int deady = 0; deady < ncols; deady++) {
int dead = birthsanddeaths.get(deadx, deady);
if (dead == -3) {
nextgeneration.set(deadx, deady, 0);
}
}
}
for (int livex = 0; livex < nrows; livex++) {
for (int livey = 0; livey < ncols; livey++) {
int live = nextgeneration.get(livex, livey);
if (live > 0 && live < kMaxAge) {
live++;
nextgeneration.set(livex, livey, live);// this doesnt work....
}
}
}
for (int newx = 0; newx < nrows; newx++) {
for (int newy = 0; newy < ncols; newy++) {
int born = birthsanddeaths.get(newx, newy);
if (born == 3) {
nextgeneration.set(newx, newy, 1);
}
}
}
return 0;
}