previous

page 6

next
gen() in functions.js
function gen() {
var temp=[];
for (var id=0;id<1600;id++) temp[id]=0;
for (var row=1;row<39;row++) {
for (var col=1;col<39;col++) {
var n=neighbours(row,col);
var id=rc2id(row,col);
var v=g_squares[id];
if (v==0) { // dead
if (n==3) v=1;
} else { // alive
if (n<2) v=0;
if (n>3) v=0;
}
temp[id]=v;
}
}
for (var id=0;id<1600;id++) {
g_squares[id]=temp[id];
}
}

Looks good but how do we know it works?

My plan is to test using a very well know pattern called the glider - you'll see why in a moment.

But how to get this pattern onto our grid? Think about it before looking at the next page.

previous
next