// title: game of life // author: Simon Cambier // desc: short description // script: js const width = 240; const height = 136; let state = []; let next = []; let generation = 0; function BOOT() { for (let i = 0; i < width; i++) { state[i] = []; next[i] = []; for (let j = 0; j < height; j++) { state[i][j] = Math.random() > .5; next[i][j] = false; } } } function TIC() { cls(13); for (let i = 0; i < width; i++) { for (let j = 0; j < height; j++) { let count = 0; // Use modulo to wrap around the edges if (state[(i - 1 + width) % width][(j - 1 + height) % height]) count++; // top left if (state[(i - 1 + width) % width][j]) count++; // top if (state[(i - 1 + width) % width][(j + 1) % height]) count++; // top right if (state[i][(j - 1 + height) % height]) count++; // left if (state[i][(j + 1) % height]) count++; // right if (state[(i + 1) % width][(j - 1 + height) % height]) count++; // bottom left if (state[(i + 1) % width][j]) count++; // bottom if (state[(i + 1) % width][(j + 1) % height]) count++; // bottom right // Currently alive if (state[i][j]) { if (count < 2) { next[i][j] = false; } else if (count > 3) { next[i][j] = false; } else { next[i][j] = true; } } // Currently dead else { if (count === 3) { next[i][j] = true; } else { next[i][j] = false; } } } } // Swap state and next // Use a temp var, otherwise state and next will be the same object let temp = state; state = next; next = temp; for (let i = 0; i < width; i++) { for (let j = 0; j < height; j++) { if (state[i][j]) { pix(i, j, 7); } } } print(`Generation: ${++generation}`, 1, 1, 0); } // // 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc // 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c // 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc // 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c // 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec // 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee // 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec // 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee // // // 000:00000000ffffffff00000000ffffffff // 001:0123456789abcdeffedcba9876543210 // 002:0123456789abcdef0123456789abcdef // // // 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000 // // // 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57 //