I need help! Conway game of life PHP version
Posted: Fri Aug 12, 2011 2:27 am
Life!
Write a program to simulate a simplified version of Conway’s Game of Life. The Game Of Life is a zero player game which starts from an initial (randomly generated) 2D array configuration and then evolves without any user input.
Assume there is no user input for this simulation. The simulation begins with a 16 x 16 2D array, which represents life. Each cell in the 2D array can be in one of two states: live or dead. Every cell in the 2D array can only interact with its surrounding 8 neighbours.
In the beginning, the program should randomly generate “dead” or “live” values for the initial configuration of the 2D array. Next, the program should generate a random number between 5 and 20, inclusive, which will be the number of times the simulation should run. For example, when 5 is randomly generated, the program should compute and display the next 5 steps of the 2D array configuration.
For each step of the simulation, the following rules must be applied to each cell:
• Any “live” cell that has less than 2 “live” neighbour cells becomes “dead” due to under-population.
• Any “live” cell that has 2 or 3 “live” neighbour cells remains “live”.
• Any “live” cell that has more than 3 “live” neighbour cells becomes “dead” due to over-crowding.
• Any “dead” cell that has exactly 3 “live” neighbour cells becomes “live” again due to reproduction.
Thus the simulation will run as follows:
• Show the initial configuration of the 2D array with the cells either “live” or “dead”
• Show the random number generated indicating the number of steps it will run
• For each step:
o Show the next configuration of the 2D array with the cells either “live” or “dead” based on the rules above.
At the end of the simulation game, the program should print the following statistics:
• Total number of initial “live” cells.
• Total number of initial “dead” cells.
• Total number of cells that went from “live” to “dead” after all the steps.
• Total number of cells that went from “dead” to “live” after all the steps.
The program must, at least, include the following methods with the correct input parameters and output types:
i. initializeFirstConfiguration, which will take as input an empty 2D array and randomly assign “live” or “dead” states to all the cells in the array
ii. generateNextConfiguration, which will accept as input the current configuration 2D array and the next configuration 2D array. It will process the current configuration 2D array by applying the rules to generate the new values in the next configuration array.
Additional info
• When finding the 8 neighbours’ values of each cell, if a cell does not have 8 neighbours (e.g. for a corner cell), then the program should just find only for those existing neighbours.
• Therefore (ii) should be as follows:
(ii) generateNextConfiguration, which will accept as input at least the current configuration 2D array and any other data as needed. It will process the current configuration 2D array by applying the rules to generate the new values in the next configuration array.
i hope you guys can help with my project
Write a program to simulate a simplified version of Conway’s Game of Life. The Game Of Life is a zero player game which starts from an initial (randomly generated) 2D array configuration and then evolves without any user input.
Assume there is no user input for this simulation. The simulation begins with a 16 x 16 2D array, which represents life. Each cell in the 2D array can be in one of two states: live or dead. Every cell in the 2D array can only interact with its surrounding 8 neighbours.
In the beginning, the program should randomly generate “dead” or “live” values for the initial configuration of the 2D array. Next, the program should generate a random number between 5 and 20, inclusive, which will be the number of times the simulation should run. For example, when 5 is randomly generated, the program should compute and display the next 5 steps of the 2D array configuration.
For each step of the simulation, the following rules must be applied to each cell:
• Any “live” cell that has less than 2 “live” neighbour cells becomes “dead” due to under-population.
• Any “live” cell that has 2 or 3 “live” neighbour cells remains “live”.
• Any “live” cell that has more than 3 “live” neighbour cells becomes “dead” due to over-crowding.
• Any “dead” cell that has exactly 3 “live” neighbour cells becomes “live” again due to reproduction.
Thus the simulation will run as follows:
• Show the initial configuration of the 2D array with the cells either “live” or “dead”
• Show the random number generated indicating the number of steps it will run
• For each step:
o Show the next configuration of the 2D array with the cells either “live” or “dead” based on the rules above.
At the end of the simulation game, the program should print the following statistics:
• Total number of initial “live” cells.
• Total number of initial “dead” cells.
• Total number of cells that went from “live” to “dead” after all the steps.
• Total number of cells that went from “dead” to “live” after all the steps.
The program must, at least, include the following methods with the correct input parameters and output types:
i. initializeFirstConfiguration, which will take as input an empty 2D array and randomly assign “live” or “dead” states to all the cells in the array
ii. generateNextConfiguration, which will accept as input the current configuration 2D array and the next configuration 2D array. It will process the current configuration 2D array by applying the rules to generate the new values in the next configuration array.
Additional info
• When finding the 8 neighbours’ values of each cell, if a cell does not have 8 neighbours (e.g. for a corner cell), then the program should just find only for those existing neighbours.
• Therefore (ii) should be as follows:
(ii) generateNextConfiguration, which will accept as input at least the current configuration 2D array and any other data as needed. It will process the current configuration 2D array by applying the rules to generate the new values in the next configuration array.
i hope you guys can help with my project