ENE 2017
Engineering Programming
Prof. Keonwook Kim
Division of Electronics and Electrical Engineering
Dongguk University, Seoul, Korea
Ch.12 Game of Life
Conway’s Game of Life makes use of sparse matrices.
Experiments with MATALB – Cleve Moler
Game of life
• Rule
• A live cell with two live neighbors, or any cell with three live
neighbors, is alive at the next step.
Experiments with MATALB – Cleve Moler
Game of life
• The beginning of the evolution of the most important five-
cell initial population, known as the glider
Experiments with MATALB – Cleve Moler
Game of life
• See the game in action
• https://www.youtube.com/watch?v=ouipbDkwHWA
• MATLAB is a convenient environment for implementing the
Game of Life.
• The population is the set of nonzero elements in the matrix.
• Store the population in a finite matrix, most of whose elements are
zero, and increase the size of the matrix if necessary when the
population expands.
Experiments with MATALB – Cleve Moler
Game of life
• Sparse matrix
• Conventional storage of an n-by-n matrix requires n memory. 2
• Sparse storage of a matrix X requires just three vectors,
• One integer and one floating point vector of length nnz(X) – the number of
nonzero elements in X
• One integer vector of length n to represent the start of each column.
• Example
• Gosper glider gun is represented by an 85-by-85 matrix with 68 nonzero
entries.
• Conventional full matrix storage would require 852 = 7225 elements.
• Sparse matrix storage requires only 2 · 65+85 = 221 elements.
Experiments with MATALB – Cleve Moler
Game of life
• The initial population is represented by a matrix of 0’s and 1’s.
• First step in the simulation.
• How many of their eight neighbors are alive.
Experiments with MATALB – Cleve Moler
Game of life
• Produces a sparse matrix with integer elements between 0
and 8 that counts how many of the eight neighbors of each
interior cell are alive.
Experiments with MATALB – Cleve Moler
Game of life
• A live cell with two live neighbors, or any cell with three live
neighbors, is alive at the next step.
Experiments with MATALB – Cleve Moler
Game of life
• Create your own fleet of gliders fleet.