Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Create Conway's Game of Life With Python (Overview)

Wouldn’t it be cool to build a Python game that only requires initial user input and then seems to take on a mind of its own, creating mesmerizing patterns along the way? You can do exactly that with Conway’s Game of Life, which is about the evolution of cells in a life grid.

Implementing the Game of Life algorithm is a good exercise with many interesting challenges that you’ll have to figure out. Specifically, you’ll need to build the life grid and find a way to apply the game’s rules to all the cells on the grid so that they evolve through several generations.

In this video course, you’ll:

  • Implement Conway’s Game of Life algorithm with Python
  • Build a curses view to display the Game of Life grid
  • Create an argparse command-line interface for the game
  • Set up the game app for installation and execution

To get the most out of this video course, you should know the basics of writing object-oriented code in Python, creating command-line interface (CLI) apps with argparse, and setting up a Python project.

Download

Sample Code (.zip)

22.0 KB
Download

Course Slides (.pdf)

1.1 MB

Eric on Feb. 18, 2024

Is there a more cross-platform friendly alternative to curses? This tutorial relies on curses for terminal text display, but this isn’t available on Windows platforms.

Bartosz Zaczyński RP Team on Feb. 19, 2024

@Eric You might have more luck with rich, which uses the ANSI escape codes under the hood.

Christopher Trudeau RP Team on Feb. 19, 2024

Hi @Eric,

I haven’t used it myself, but the documentation:

docs.python.org/3/howto/curses.html

mentions a Window port:

pypi.org/project/UniCurses

that is supposed to be a drop-in replacement.

Eric on Feb. 19, 2024

Hi Christopher and Bartosz, thank you for your replies. I hacked my way through it using a TextView using printf(); not pretty but let me get on to the more interesting part about packaging and distribution.

I’ve taken a quick look at unicurses and think its worth sharing the following.

  • unicurses: The link to the UniCurses port isn’t hosted on PyPI and seems very out of date: the download links to source-forge with a 2010 release date and only has a few 1* reviews, but helpfully point to Windows-Curses.

  • Windows-Curses (pypi.org/project/windows-curses/) appears significantly more active, is installable via pip, and was last released in October 2023. It’s imported via curses so should only need a new (platform-specific) line in the pyproject.toml:[project]:dependencies lines. It seems to drop in nicely to the CursesView implemented in this video.

I’ll look at rich next!

Christopher Trudeau RP Team on Feb. 20, 2024

Hi @Eric,

With rich you’ll be able to create the project, but the commands for the display will be different. Likewise with another library that may work for you: asciimatics. If you’re comfy playing with different screen display code, you’ll be good, but the approach will be different.

The code is designed around having multiple visualization implementations, with the curses code going in the “views.py” file. In your case, you’d be implementing a different view, but if you use the same interface, the rest of the code should work. Good luck with it, and please leave a comment when you’ve got your solution, others will be interested as well.

Become a Member to join the conversation.