Game of Life in JavaScript

VN:F [1.9.11_1134]
Rating: -1 (from 1 vote)
VN:F [1.9.11_1134]
Rating: 0.0/5 (0 votes cast)

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.

2 Responses to “Game of Life in JavaScript”

  1. cr0acker said:

    Jan 25, 09 at 2:17 PM

    Last 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

    VA:F [1.9.11_1134]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.11_1134]
    Rating: 0 (from 0 votes)
  2. Shaos said:

    Jan 25, 09 at 6:24 PM

    That’s correct – I don’t like JavaScript, but it’s more than enough to demonstrate some concepts directly on Web-pages…

    VA:F [1.9.11_1134]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.11_1134]
    Rating: 0 (from 0 votes)

Leave a Reply

You must be logged in to post a comment.