Question: Neighbor count not updating in real - time. Values are behind one generation when the simulation is ran. Initially shows up correctly. Falls behind one
Neighbor count not updating in realtime. Values are behind one generation when the simulation is ran. Initially shows up correctly. Falls behind one generation when the simulation is ran.void MainWindow::CalculateNextGeneration
std::vector sandboxgameBoardsize std::vectorgameBoardsize false;
std::vector newNeighborCountgameBoardsize std::vectorgameBoardsize;
int newLivingCellCount ;
Calculate new neighbor counts and update cell states
for int i ; i gameBoard.size; i
for int j ; j gameBoardisize; j
int neighbors CalculateLivingNeighborsi j;
newNeighborCountij neighbors;
if gameBoardij
if neighbors neighbors
sandboxij false; Cell dies
else
sandboxij true; Cell lives
newLivingCellCount;
else
if neighbors
sandboxij true; Cell becomes alive
newLivingCellCount;
else
sandboxij false; Cell remains dead
Update the neighbor count, living cell count, and generations
livingCells newLivingCellCount;
generations;
drawingPanelUpdateNeighborCountnewNeighborCount;
Update the game board with the new generation
gameBoard.swapsandbox;
Update status text
UpdateStatusBar;
Update the neighbor count, living cell count, and generations in the drawing panel
drawingPanelUpdateLivingCellCountlivingCells;
drawingPanelUpdateGenerationsgenerations;
Refresh the drawing panel
Refresh;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
