17. Conway’s Game of Life

How do you get to Carnegie Hall? Practice, practice! Now answer this: how do you become a programmer?

The answer is to practice on what I call “real projects.” That’s why I focused on Tic-Tac-Toe in Chapter 14. Playing a perfect strategy—even for this simple game—is far from trivial. It required serious mastery of Python fundamentals, as well as creative decision-making.

In this chapter, I’ll apply Python tricks introduced in the last few chapters to an even more ambitious project: Conway’s Game of Life, which simulates living cells! That this entire program can be written in 100 lines (38 if you take out the comments and blank lines!) is remarkable. The strategy of this chapter is

Develop a general-purpose matrix class ...

Get Python Without Fear now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.