Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
The code for this chapter is in the notebook chap08.ipynb in the repository for this book. Open this notebook, read the code, and run the cells. You can use this notebook to work on the following exercises.
Exercise 1: Start GoL in a random state and run it until it stabilizes. What stable patterns can you identify?
Exercise 2: Many named patterns are available in portable file formats. Modify
Life.py to parse one of these formats and initialize the grid.
Exercise 3: In the given implementation, the
Life class is based on a parent class called
Cell2D, and the
LifeViewer class is based on
Cell2DViewer. You can use these base classes to implement other 2-D cellular automatons.
For example, one variation of GoL, called “Highlife”, has the same rules as GoL, plus one additional rule: a dead cell with 6 neighbors comes to life.
Write a class named Highlife that inherits from
Cell2D and implements this version of the rules. Also write a class named
HighlifeViewer that inherits from
Cell2DViewer and try different ways to visualize the results. As a simple example, use a different colormap.
One of the more interesting patterns in Highlife is the replicator. Use
add_cells to initialize Highlife with a replicator and see what it does.
Exercise 4: If you generalize the Turing machine to two dimensions, or add a read-write head to a 2-D CA, the result is a cellular automaton called a Turmite. It is named after a termite because of the way the read-write head moves, but spelled wrong as an homage to Alan Turing.
The most famous Turmite is Langton’s Ant, discovered by Chris Langton in 1986.
The ant is a read-write head with four states, which you can think of as facing north, south, east or west. The cells have two states, black and white.
The rules are simple. During each time step, the ant checks the color of the cell it is on. If black, the ant turns to the right, changes the cell to white, and moves forward one space. If the cell is white, the ant turns left, changes the cell to black, and moves forward.
Given a simple world, a simple set of rules, and only one moving part, you might expect to see simple behavior — but you should know better by now. Starting with all white cells, Langton’s ant moves in a seemingly random pattern for more than 10,000 steps before it enters a cycle with a period of 104 steps. After each cycle, the ant is translated diagonally, so it leaves a trail called the “highway”.
Write an implementation of Langton’s Ant.