For the second project deliverable,
you will implement a version of
Conway's Game of Life (CGoL).
The key notion of CGoL is that each cell lives or dies
according to these simple rules:
You will want to think about how to decompose the problem into simple functional chunks. You should define a type, grid, using Scheme vectors. That is, the grid should be a (vectorof (vectorof cells)), where a cell is defined by you and represents a state. You will want a function that displays a given grid. It may be helpful to think of the grid as a vector of rows, each of which is a vector of cells in columns.
Ultimately, you must write a function, cgol, that consumes a number and a grid: the number specifies how many generations to simulate, and the grid represents the initial state of the cellular automata. The number of rows and columns necessarily follows from the initial grid; this will determine the height and width of your display based on the size of a cell. The cgol function simulates the game of life for the appropriate number of generations using the initial grid. Make sure that your code works with different dimensions of initial grids. For each generation, the life-status of each cell should be checked and updated according to the rules given above, and then the grid should be redrawn.
You should include a global identifier, WRAP?. When true, the grid should wrap from edge to edge and top to bottom. That is, a cell along the bottom edge has five neigbors immediately adjacent, and three more neighbors along the top row of the gird. Likewise, the cell in the upper left corner has neighbors that include the lower right corner, the two-leftmost cells in the last row, and the right-mose cells in the top two rows. When WRAP? is false, you should perform updates as if the grid is ringed by a border of dead cells that never come to life.
Make sure that the new life-status of one cell does not interfere with the update of an adjacent cell. Use the big-bang function provided by 2htdp/universe, together with 2htdp/image teachpacks to create the animation. Cells may be rendered as either circles or squares, but the live or dead status of cells should be represented by two easily distinguished colors.
For a given cell dimension size, d, and a given grid, G, your display image would be d * (vector-length G) pixels tall, and d * (vector-length (vector-ref G 0)) pixels wide.
Do not forget to include the standard acknowledgements header at the top of your file. To grade this deliverable, I will review your code (including contracts, purpose statements, test cases, indentation, etc.), and then call cgol with a given number of steps to simulate and an initial organism of my choosing.
Submit a single file with your username followed by “P2.rkt” as the name of the file, which should contain your code fulfilling the above requirements as well as your acknowledgements.