Q!·ÆúUXü;¿Z¬E°ØéRßNvnà¢%CQ®M{"__cls":"class GOL {\r\n constructor(n) {\r\n this.n = n\r\n this.gridHeight = n\r\n this.gridWidth = n\r\n }\r\n createArray(rows) { //creates a 2 dimensional array of required height\r\n var arr = [];\r\n for (var i = 0; i < rows; i++) {\r\n arr[i] = [];\r\n }\r\n return arr;\r\n }\r\n fillRandom() { //fill the grid randomly\r\n let j = 0\r\n let k = 0\r\n for (j; j < gridHeight; j++) { //iterate through rows\r\n for (k; k < gridWidth; k++) { //iterate through columns\r\n var rawRandom = Math.random(); //get a raw random number\r\n var improvedNum = (rawRandom * 2); //convert it to an int\r\n var randomBinary = Math.floor(improvedNum);\r\n if (randomBinary === 1) {\r\n theGrid[j][k] = 1;\r\n } else {\r\n theGrid[j][k] = 0;\r\n }\r\n }\r\n }\r\n }\r\n updateGrid() { //perform one iteration of grid update\r\n let j = 1\r\n let k = 1\r\n for (j; j < gridHeight; j++) { //iterate through rows\r\n for (k; k < gridWidth; k++) { //iterate through columns\r\n var totalCells = 0;\r\n let j0 = j - 1\r\n let k0 = k - 1\r\n let j1 = j +1\r\n let k1 = k +1\r\n //add up the total values for the surrounding cells\r\n totalCells += theGrid[j0][k0]; //top left\r\n totalCells += theGrid[j0][k]; //top center\r\n totalCells += theGrid[j0][k1]; //top right\r\n totalCells += theGrid[j][k0]; //middle left\r\n totalCells += theGrid[j][k1]; //middle right\r\n totalCells += theGrid[j1][k0]; //bottom left\r\n totalCells += theGrid[j1][k]; //bottom center\r\n totalCells += theGrid[j1][k1]; //bottom right\r\n //apply the rules to each cell\r\n if (theGrid[j][k] === 0) {\r\n switch (totalCells) {\r\n case 3:\r\n mirrorGrid[j][k] = 1; //if cell is dead and has 3 neighbours, switch it on\r\n break;\r\n default:\r\n mirrorGrid[j][k] = 0; //otherwise leave it dead\r\n }\r\n } else if (theGrid[j][k] === 1) { //apply rules to living cell\r\n switch (totalCells) {\r\n case 0:\r\n case 1:\r\n mirrorGrid[j][k] = 0; //die of lonelines\r\n break;\r\n case 2:\r\n case 3:\r\n mirrorGrid[j][k] = 1; //carry on living\r\n break;\r\n case 4:\r\n case 5:\r\n case 6:\r\n case 7:\r\n case 8:\r\n mirrorGrid[j][k] = 0; //die of overcrowding\r\n break;\r\n default:\r\n mirrorGrid[j][k] = 0; //\r\n }\r\n }\r\n }\r\n }\r\n //copy mirrorGrid to theGrid\r\n let y = 0\r\n let z = 0\r\n for (y; y < this.gridHeight; y++) { //iterate through rows\r\n for (z; z < this.gridWidth; z++) { //iterate through columns\r\n theGrid[y][z] = mirrorGrid[y][z];\r\n }\r\n }\r\n }\r\n tick() { //main loop\r\n //drawGrid();\r\n updateGrid();\r\n //requestAnimationFrame(tick);\r\n }\r\n}","__index":{"obj":0},"__func":"constructor","__args":[10]}u
https://whatsonchain.com/tx/undefined