This game is a type of cellular automata and simulates a simplified grid world.
For our purposes, the grid will consist of 40 rows and 80 columns. Each spot in the grid can either be empty, or have a live cell in it. The simulation consists of successive generations. At each generation, the following rules are applied:
Here "neighbors" refers to live cells that are to the left, right, top, bottom or diagonal of the cell. A cell can have from zero to eight neighbors.
Note that the neighbors count cells that are live in this generation, regardless of whether or not they will be live the next.
Your program should take two parameters. First is the name of the input file. This file contains a bit for each cell in the grid. There are $40 \times 80 = 3200$ bits which is equal to $3200 \div 8 = 400$ bytes.
If a bit is 1, that means the corresponding cell is alive. If it is 0, it means that cell is dead.
The first byte stores the first eight cells from the first row of the grid world. The most significant bit in the byte comes first, so location (0, 0) is given by the most significant bit of the first byte in the file.
To see if a given cell is alive, you need to first find which of the 400 bytes it is in, and then test the individual bit in that byte.
The second parameter is a positive integer, $N$, which indicates the number of generations to simulate.
Your program should simulate $N$ generations, according to the rules above, and output the final state of the grid to the screen. Any dead cells should be output as spaces, and live cells should be output with the 'O' character.
You can test your program with the following input files.
|Test Files||Output After 100 Generations|
When your program works, email the source code to email@example.com.
Copyright © 2021 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.