Computer Laboratory > Teaching > Course material 2009–10 > ECAD Labs > ECAD Lab 2 - Game of Life > Game of Life

  Game of Life

In this final part of the lab, you need to implement the nextstate function whose outline was given in the assembler code on the previous page. This should take the current state of the game from the frame buffer, compute the next state, storing this in memory, and once this has been completed copy the contents of the memory back into the frame buffer. To load the base address of the temporary memory into a register, use la $rd store_data where $rd is the destination register.

The rules for calculating the next state of a cell given its current state and the surrounding cells are:

  • Any live cell with fewer than 2 live neighbours dies.
  • Any live cell with more than 3 live neighbours dies.
  • Any live cell with 2 or 3 live neighbours lives to the next generation.
  • Any dead cell with exactly 3 live neighbours comes to life.
For cells that lie on the edge of the grid, their non-visible neighbours should be assumed to be dead cells.

The nextstate function should be called when KEY3 is pressed on the board. The code to do this will be the same style as for the mouse button handler. You might also like to have a "run" or "auto-repeat" mode, e.g. when SW0 is "on" the nextstate function is called at a reasonable rate.

Once this is working, you should be able to toggle squares on and off with the mouse, as well as advance the state by one generation by pressing the key. If you start with the initial pattern given to you, and simply keep advancing the state again and again, you should notice a stream of gliders moving diagonally down the screen. The initial pattern pattern gives a glider gun, whereby the pattern is in a loop, and continuously emits a stream of gliders from it.

The second lab is now finished :-)


You may find the program Game of Life program useful for debugging. This is a working version of the Game of Life designed to have the same size grid and semantics as the lab exercise. You can open .mif files that are in the correct format and it will display them on screen (try opening initial.mif from your project directory). You can toggle squares with the mouse and also save the current state of the grid on screen. This will enable you to create your own default pattern, simply save the file as initial.mif in your project directory, update the Memory Initialisation Files by selecting Processing | Update Memory Intialisation File, then run the assembler by selecting Processing | Start | Start Assembler. Finally, re-program the device and your new pattern should be displayed on the screen.