Book Image

NumPy: Beginner's Guide

By : Ivan Idris
Book Image

NumPy: Beginner's Guide

By: Ivan Idris

Overview of this book

Table of Contents (21 chapters)
NumPy Beginner's Guide Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
NumPy Functions' References
Index

Simulation game with Pygame


As a last example, we will simulate life with Conway's Game of Life. The original game of life is based on a few basic rules. We start out with a random configuration on a two-dimensional square grid. Each cell in the grid can be either dead or alive. This state depends on the neighbors of the cell. You can read more about the rules at http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#Rules At each step in time, the following transitions occur:

  1. Live cells with less than two live neighbors die.

  2. Live cells with two or three live neighbors live on to the next generation.

  3. Live cells with more than three live neighbors die.

  4. Dead cells with exactly three live neighbors become a live cell.

Convolution can be used to evaluate the basic rules of the game. We need the SciPy package for the convolution process.