Saturday, January 24, 2009
Game of Life in JavaScript
Today I implemented my old (1994) "fast enough" algorithm of Game of Life in JavaScript (see source code here - life.js) and now LIFE table can be "embedded" directly to HTML:
Usually programs of LIFE operate two 2-dimensional arrays of booleans calculating neighbours for every cell in every generation by walking through nearest 8 cells for each cell on map and modifying second array according to LIFE rules (alive cell will live if it has 2 or 3 alive neighbours, dead cell will be alive again if it has exactly 3 alive neighbours, otherwise cell must be dead) as a buffer to copy it to primary array later at the end of calculation for each generation. My algorithm uses precalculated number of neighbours for each cell walking through nearest 8 cell ONLY if something changed inside cell (transition from dead to alive or from alive to dead) to decrease or increase number of neighbours in 8 nearest cells respectively.
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 2 | 3 | 5 | 3 |
| 0 | 0 | 0 | 0 | 0 | 0 | 2 | 2 | 3 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 3 | 2 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Usually programs of LIFE operate two 2-dimensional arrays of booleans calculating neighbours for every cell in every generation by walking through nearest 8 cells for each cell on map and modifying second array according to LIFE rules (alive cell will live if it has 2 or 3 alive neighbours, dead cell will be alive again if it has exactly 3 alive neighbours, otherwise cell must be dead) as a buffer to copy it to primary array later at the end of calculation for each generation. My algorithm uses precalculated number of neighbours for each cell walking through nearest 8 cell ONLY if something changed inside cell (transition from dead to alive or from alive to dead) to decrease or increase number of neighbours in 8 nearest cells respectively.
Labels: game_of_life, programs
Tuesday, April 15, 2008
"Game of Life" evolution network
Some time ago I registered domain LifeGE.net. Main idea of LifeGE.net was creating place to discuss some techniques for automatic design of some Conway's Game of Life patterns for implementation of real computer over Game of Life. I plan to use genetic algorithms for search of that patterns and also I need help of Internet people and their CPU cycles ;)
P.S. You can read about cellular automata "Conways's Game of Life" on Wikipedia.
P.S. You can read about cellular automata "Conways's Game of Life" on Wikipedia.
Labels: distributed_computing, game_of_life, genetic_algorithms
Subscribe to Posts [Atom]
