Answered step by step
Verified Expert Solution
Question
1 Approved Answer
So, for this step, change your life function so that it calls a new function named updateNextLife( oldB, newB ) in place of updateReversed, above.
So, for this step, change your life function so that it calls a new function named updateNextLife( oldB, newB ) in place of updateReversed, above. Then, implement the updateNextLife ( oldB, newB ) function so that it sets each cell in the new data according to the updating rules based on the old generation, oldB: 1. A cell that has fewer than two live neighbors dies (because of loneliness) 2. A cell that has more than 3 live neighbors dies (because of over-crowding) 3. A cell that is dead and has exactly 3 live neighbors comes to life 4. All other cells maintain their state As suggested in updateReversed, always keep all of the outer-edge cells empty. This is simply a matter of limiting your loops to an appropriate range. However, it greatly simplifies the four update rules, above, because it means that you will only update the interior cells, all of which have a full set of eight neighbors. You may want to write a helper function, countNeighbors for example, for determining the number of live neighbors for a cell in the board at a particular row and col. Hints Count neighbors only in the old generation oldB. Change only the new generation, newB. - Be sure to set every value of newB (the new data), whether or not it differs from oldB. - A cell is NOT a neighbor of itself
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started