This is an implementation of Conway's Game of Life in Python.
From Wikipedia:
- The universe of the Game of Life is an infinite, two-dimensional orthogonal grid of square cells
- Each cell is in one of two possible states, live or dead.
- Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent.
- At each step in time, the following transitions occur:
- Any live cell with fewer than two live neighbours dies, as if by underpopulation.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overpopulation.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
- These rules can be condensed into the following:
- Any live cell with two or three live neighbours survives.
- Any dead cell with three live neighbours becomes a live cell.
- All other live cells die in the next generation. Similarly, all other dead cells stay dead.
- Input file name, output file name, and number of generations are provided as arguments to the script.
- The script reads the size of the grid and the initial pattern from the input file.
- It applies the rules for the number of generations indicated as an argument.
- It writes the final pattern to the output file.
- The first line indicates the width and height of the grid as unsigned integer values separated by a space.
- The other lines indicate the initial locations of the living cells. Each line has two unsigned integer values separated by space indicating vertical and horizontal coordinates of the living cells, respectively.
- The top left cell has the coordinates of (0, 0)
- Valid vertical coordinate values range between 0 - (height-1), increasing from top to bottom.
- Valid horizontal coordinate values range between 0 - (width-1), increasing from left to right.
python game.py input.txt output.txt 2
Input:
5 5
0 0
2 1
2 2
3 2
3 4
Output:
5 5
1 1
2 3
3 1
3 3
4 2