Tuesday, January 12, 2021

Well, it's just Life

In October of 1970, a columnist writing for Scientific American named Martin Gardner published a letter he received the previous March from John Conway, a mathematician at the University of Cambridge titled "The Game of Life."  Life was created 50 years ago.  Who knew?  Seriously, you can read all of Martin Gardner's articles on "The Game of Life" in his book Wheels, Life and other Mathematical Amusements.  The articles on Life can also be found collected in this PDF.

If you studied math or computer science in college, you may have come across Conway's Game of Life.  Its rules are very simple, and thus easy for beginning computer programmers to get their heads around.  So, it often got co-opted by professors as a coding project.  I'm not sure I ever crossed paths with it myself during my education, but I found myself fascinated by it over the 2020 Christmas break after reading the article "The Lasting Lessons of John Conway's Game of Life" in my local paper, sited here where it was originally published in the New York Times.

I wanted to learn to "play" Life the way it was intended to be played before I dove right in and played it software assisted.  So, I started with a spreadsheet, and the rules in the articles above.  I formatted it into a grid of squares and started working through the various Tetrominoes, the famous square patterns used in the game of Tetris.  The T-Tetromino was the most interesting of these in the Game of Life, as you can see from my spreadsheet pictured below.

The Game of Life - Manual Edition

As you can see, the T-Tetromino results is a repeating pattern after 9 generations.  Things get much more interesting and complicated once you get beyond 4 block patterns, so I found myself in search of software.  The most commonly used open source project for the game of life is Golly.  It is a very mature, and extremely powerful implementation of the Game of Life for all modern desktop operating systems.

Golly with the R-Pentomino

Just adding a single block to the T-Tetromino creates the R-Pentomino.  It will generate life that goes well past 1000 generations, including most of the well-known stable forms, including ones that move in stable ways like the glider.

As powerful as Golly is, I found myself wanting something less robust, something that I could use to step through one generation at a time so I could see things unfolding much more slowly.  So I decided to code my own implementation.  I've been doing a lot of work in my lab in Python of late, more on that soon, so I chose Python as my language of choice.  This seemed like a great way to learn how to write cross-platform GUI applications in Python.  I've some experience with Tk/TCL, which the tkinter library supports, but I wanted to learn something new.  So, I decided on wxPython, which is an interface to the wxWidgets library.  It did the job nicely.

My Game of Life Implementation on Generation 84 of the R-Pentomino

In my version, you can either step through one generation at a time, or you can play it forward, but only at a speed of one generation per second, so you can see life unfold a a more relaxed pace.  This was a fun project.  Feel free to explore my source code if you are interested.  It can be found here.  Please be kind.  I'm pretty new to Python programming in general, and this was my first wxPython project.  Still, it was a pretty easy.  I'll likely do more wxPython work in the future as the need arises here in the lab.

If you want to learn more about the Game of Life, you can lose yourself for longer than the lifespan of the R-Pentomino at LifeWiki.  It is essentially the sum of all human knowledge about the Game of Life.  I guess the name "Bible" was already taken.


No comments:

Post a Comment

Enigma in Software

  My Software Enigma Machine Simulator In a previous post, I shared my long-held fascination with the Enigma cipher machine used by the Germ...