Feel free to contact me
This is a implementation of 2 players Conway’s Game of life with variations. The Game of Life is played on a grid of cells, where each cell is either dead or alive. For each “turn” or “generation” of the game, the game iterates over all of the cells and determines whether a cell is alive or dead based on a set of rules.
The rules for the standard single player version are as follows:
Neighboring cells are cells adjacent to the cell (up to 8 cells). The alive or dead state is determined simultaneously for all cells.
In this project for two player Game of Life, each cell is either dead, contains an alive cell owned by Player 1 or an alive cell owned by Player 2.
The rules for the two player Game of Life are then as follows:
The game continues creating new generations until one player no longer has any more live cells. The player with remaining live cells is the winner. If both players’ remaining cells die simultaneously, a tie is declared.
This is a Java program that will play the two player Game of Life.
The format of the initial generation file is as follows:
The remaining lines specify the state of the initial generation. Each line is a row in the grid where the state of each cell is a character in that line. There is a character for each column in the grid. The state of a cell is specified as follows:
Here is an example initial generation file: 10 10
..........
..1.......
...1......
..111.....
..........
.......22.
......2..2
.......22.
..........
..........
When the program starts, it reads the initial generation file and validates that it is correct. An invalid ini- tial generation file is one that does not follow the specification. If the program determines that the initial generation file is invalid, it displays an error message and terminates.
After the initial generation file is read, the program prints the state of the generation. The state of the generation consists of:
For the example initial generation file above, the program prints out the following state:
Generation #0
Player 1 Cells: 5
Player 2 Cells: 6
..........
..1.......
...1......
..111.....
..........
.......22.
......2..2
.......22.
..........
..........
The program then generates the next state given the initial state and prints out the state in the same format
as the initial state:
Generation #1
Player 1 Cells: 5
Player 2 Cells: 6
..........
..........
....1.....
..111.....
...1......
.......22.
......2..2
.......22.
..........
..........
The program checks to see if one of the players no longer has any live cells. If so, the program prints out the winner and how many cells that player has remaining:
Player 1 Wins! with 11 live cells
Game Over!!
If both players no longer have any live cells, the program prints out there is a tie and then terminates. Otherwise, the program continues generating new states, printing out the state and determine whether or not there is a winner until a winner is declared or the program is terminated.
I encourage you to test and play the Game of Life, its real fun!!. Send your pull requests with improvements and suggestions to make the game even more fun.