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:
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.
cr0acker said:
Jan 25, 09 at 2:17 PMLast time we discussed javascript, you said that you do not like to much. So i am waiting for Life written in pure java with Java/PulpCore
Shaos said:
Jan 25, 09 at 6:24 PMThat’s correct – I don’t like JavaScript, but it’s more than enough to demonstrate some concepts directly on Web-pages…