In addition to not really creating a new temp array but just getting a reference to old one, as said in other answers: you copy the tempGrid
cell into the grid
cell in the same loop where you calculated it. So next loop iteration will use the new calculated value, instead of the current "old" value in grid.
You need to first calculate entire tempGrid
, and then copy it over grid
. Or better than copying, would be to set grid to point to tempGrid's array, but that might be out of scope of your homework (you would have to return tempGrid
from genNextGrid()
and assign it to original grid reference).
The whole point of needing a tempGrid
instead of just single temp cell is, you need the previous generation in grid
during calculation of next generation.