Woo Woo
An interesting video led me to try the speaker’s idea for Game of Life. That led me to a very strange thought. And I’m not even stoned. Also: Love one another.
Trey Hunner runs Python Morsels site offering Python training. I have not subscribed to any of his training but have viewed some of the free ones and subscribe to his mailing list, where he sends out interesting, not too salesy, notes.
This week, he pointed to a talk by Jack Diederich, Stop Writing Classes, which I watched and enjoyed, although I do not intend to stop writing classes. As part of his talk, Jack talks about Conway’s Game of Life, and shows a sketch of a class-based version which he reduces to a couple of functions. As you’ll see below, the code is quite compact and does the job.
- Game of Life
- If you are not familiar with Conway’s Game of Life, you are one of today’s lucky 10,000, because it is a fascinating, very simple cellular automaton that can generate fascinating and complex patterns. It is Turing complete, which means that in principle there is a starting configuration that can compute any computable function. There are on-line implementations of the game, and it is quite fun to implement it on one’s own … although that will never be the same for me after what I did today, copying Jack’s version.
-
The Wikipedia Article is a good introduction to the game, its rules, and its history.
Here is a short video showing the “glider” pattern, cycle after cycle:
We see that the glider pattern goes through 4 cycles to replicate itself a bit further down and to the right. It will stay alive forever, traveling south east, unless it collides with something else. There are patterns like glider gun, that create an infinite number of gliders, patterns that create an infinite number of glider guns, it goes on and on. Truly fun and fascinating if you are that kind of person, which I certainly am.
Woo Woo
Here’s the woo woo observation that I came up with this morning while trying not to get up yet. We see that little constellation of dots moving across the screen. We call it a “glider”. We can point to it, think about it, look at its cycles.
But the thing is this: there is no thing there. There is no glider. (Also, no spoon, but that’s another story, although come to think of it maybe it’s not.)
Now, I don’t just mean there is no glider because it’s just dots on a screen. I mean that the cellular automaton we have implemented does not contain an object that we can point to and say “there’s the glider”. At one point, these cells are alive:
(20, 20), (30, 30), (10, 40), (30, 40), (20, 40)
Four cycles later, these are alive:
(30, 50), (40, 50), (30, 30), (20, 50), (40, 40)
There is no “thing” that is the glider that we see on the screen, moving along. There is just the automaton, processing all its cells, turning them on and off according to the simple local rule.
OK, that’s a bit woo woo, I hope you’ll agree: when we look at what is displayed, we see the glider and can discuss its behavior. But in the actual automaton there is no glider concept at all. There is no concept of pattern at all. There is just a world of cells that are alive or dead.
But wait, there’s more!
Stephen Wolfram, the genius entrepreneur who invented Mathematica, studied cellular automata in his book A New Kind of Science, argues that the universe we live in is discrete and runs according to simple rules, though not quite so simple as Game of Life. The book and the assertion are criticized for a number of reasons, including the fact that Wolfram offers no evidence supporting the assertion.
But … suppose that it’s true that the universe is some kind of machine, and that it is not a continuous function, but a discrete one. At least some theories of the universe allow for space to be discrete, not continuous.
So if the universe works like a giant cellular automaton, there is no glider in it. There is no galaxy, no sun, no planet Earth, no Michigan, no you: there are just patterns that we recognize as those things.
Is that woo woo enough for you? And I’m not even stoned, nor am I a sophomore, although I surely am a fool if not a wise one.
Love one other, even if we are all just patterns in the machine. We think, we feel, we hurt, we experience joy. Love one another.
Here’s the complete code that produced the video above:
import itertools
import sys
import pygame
def advance(board):
new_state = set()
recalc = board | set(itertools.chain(*map(neighbors, board)))
for point in recalc:
count = sum((neigh in board)
for neigh in neighbors(point))
if count == 3 or (count == 2 and point in board):
new_state.add(point)
return new_state
def neighbors(point):
x, y = point
yield x + 1, y
yield x - 1, y
yield x, y + 1
yield x, y - 1
yield x + 1, y + 1
yield x + 1, y - 1
yield x - 1, y + 1
yield x - 1, y - 1
automaton = set([(0, 0), (1, 0), (2, 0), (2, 1), (1, 2)])
pygame.init()
screen = pygame.display.set_mode((800,800))
pygame.display.set_caption('Life')
while True:
pygame.time.delay(250)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill("midnightblue")
for point in automaton:
x, y = point
dx = x*10 + 10
dy = -y*10 + 40
pygame.draw.circle(screen, "white", (dx, dy), 5, 0)
automaton = advance(automaton)
pygame.display.flip()