![]() ![]() I decided to take advantage of NumPy to simplify the calculations with the tradeoff being that the initial set up was a little bit more complicated to figure out. This approach has several pitfalls: manual indexing (a nightmare), and the necessity for manually updating a new array (you can’t update any of the cells until you’ve checked all of them and have determined their next state, since updating one cell could potentially change the number of neighbors of the next cell). ![]() ImplementationĬonventionally, one might take a looping approach where each cell is checked and updated individually, cell-by-cell. The first two transitions reflect the first rule:Īny live cell with two or three live neighbors survivesĪnd the third transition corresponds to the second rule:Īny dead cell with exactly three live neighbors becomes a live cellĮvery other possible state (again, a 2-tuple (alive or dead, number of neighbors)) results in either a live cell dying or a dead cell staying dead. Taking this into account, there are actually only three state transitions which we really care about: There’s no functional difference between (0, 5) -> 0 and (0, 7) -> 0, for example. Notice that the vast majority of the state transitions are equivalent based on those three rules from earlier. As you can see, the next state of that cell is 0, meaning the cell stays dead. So for instance, the state transition (0, 5) -> 0 applies to any cell which is dead (the 0 in the 2-tuple) and which has five living neighbors (the 5 in the 2-tuple). ![]() The way to read these state transitions is from left to right: on the left hand side is a 2-tuple containing the current state of any given cell and the number of living neighbors it has, and the right hand side is the next state of that cell. Since there are two states in which a cell can be observed and anywhere from 0 to 8 living neighbors, it’s entirely possible to enumerate all the possible state transitions, which is the cartesian product of for a total of 18 possible state transitions: Familiarity with discrete finite state machines would be helpful here, but is not necessary. The word state in this section will specifically refer to the status (alive or dead) of an individual cell. Here’s a cell outlined in yellow and its eight neighbors and their statuses: Determine whether that cell should die, survive, or be rebornĮach cell’s neighborhood consists of the eight cells adjacent to it (up, down, left, right, and the diagonals).For a given cell, count how many living neighbors it has.The basic algorithm for implementing Life is as follows: All other live cells die in the next generation (all dead cells stay dead).Any dead cell with exactly three live neighbors becomes a live cell.Any live cell with two or three live neighbors survives.Those are the original rules, but they can actually be consolidated to only three rules: Reproduction: a dead cell with exactly three neighbors is reborn.Overpopulation: a live cell with four or more live neighbors dies.Survival: a live cell with two or three neighbors survives.Underpopulation: a live cell with zero or one live neighbors dies. ![]() The state at time t is entirely determined by the state at time t - 1, and is governed by this simple rule set: Going forward I’ll be referring to this collection of cells as cells and the overall state of the cells at any given time as state. The Game of Life is a 2-dimensional array of cells which observe a binary state: either on or off, alive or dead. When I looked up the ruleset, I realized I had no excuse.įor those unfamiliar, Conway’s Game of Life is what is known as a cellular automaton. I had always been very intrigued by Conway’s Game of Life but had never actually implemented it myself. Kok’s galaxy and 68P9 are then reflected horizontally on the right. See the source code here.įrom left to right: Kok’s galaxy, a period-8 oscillator 68P9, a period-9 oscillator and 2.2.6, a period-2 oscillator. A NumPy-oriented implementation of Conway’s Game of Life with options for fixed or periodic boundary conditions. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |