#0
nonstandard
0.00004000 BSV
Q!·ÆúUXü;¿Z¬E°ØéRßNvnà¢%CQ®M<{"__cls":"class GOL {\r\n constructor(n) {\r\n this.gridHeight = n\r\n this.gridWidth = n\r\n this.theGrid = this.createArray(n)\r\n this.mirrorGrid = this.theGrid\r\n this.Counter = 0\r\n }\r\n\r\n createArray(rows) {\r\n var arr = [];\r\n for (var i = 0; i < rows; i++) {\r\n arr[i] = [1];\r\n var rawRandom = Math.random();\r\n var improvedNum = (rawRandom * 2);\r\n var randomBinary = Math.floor(improvedNum);\r\n if (randomBinary === 1) {\r\n arr[i] = [1];\r\n } else {\r\n arr[i] = [0];\r\n }\r\n }\r\n return arr;\r\n }\r\n\r\n updateGrid() {\r\n this.Counter = this.Counter + 1\r\n let tC = 0\r\n let tCt = ''\r\n let check = 0\r\n for (var j = 1; j < this.gridHeight - 1; j++) { //iterate through rows\r\n for (var k = 1; k < this.gridWidth - 1; k++) { //iterate through columns\r\n tC = 0\r\n tCt = 0\r\n //add up the total values for the surrounding cells\r\n tCt = this.theGrid[j - 1], [k - 1] //top left\r\n tC = tC + parseInt(tCt)\r\n tCt = this.theGrid[j - 1], [k] //top center\r\n tC = tC + parseInt(tCt)\r\n tCt = this.theGrid[j - 1], [k + 1] //top right\r\n tC = tC + parseInt(tCt)\r\n tCt = this.theGrid[j], [k - 1] //middle left \r\n tC = tC + parseInt(tCt)\r\n tCt = this.theGrid[j], [k + 1];//middle right\r\n tC = tC + parseInt(tCt)\r\n tCt = this.theGrid[j + 1], [k - 1] //bottom left\r\n tC = tC + parseInt(tCt)\r\n tCt = this.theGrid[j + 1], [k] //bottom center\r\n tC = tC + parseInt(tCt)\r\n tCt = this.theGrid[j + 1], [k + 1] //bottom right\r\n tC = tC + parseInt(tCt)\r\n\r\n //apply the rules to each cell\r\n tCt = this.theGrid[j], [k]\r\n check = 0\r\n check = parseInt(tCt)\r\n console.log(check)\r\n\r\n if (check === 0) {\r\n console.log('O')\r\n switch (tC) {\r\n case 3:\r\n console.log('1_3')\r\n this.mirrorGrid[j], [k] = [1]; //if cell is dead and has 3 neighbours, switch it on\r\n break;\r\n default:\r\n console.log('1_d')\r\n this.mirrorGrid[j], [k] = [0]; //otherwise leave it dead\r\n break;\r\n }\r\n break;\r\n } else {//apply rules to living cell\r\n console.log('X')\r\n switch (tC) {\r\n case 0:\r\n case 1:\r\n console.log('2_01')\r\n this.mirrorGrid[j], [k] = [0]; //die of lonelines\r\n break;\r\n case 2:\r\n case 3:\r\n console.log('2_23')\r\n this.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 console.log('2_45678')\r\n this.mirrorGrid[j], [k] = [0]; //die of overcrowding\r\n break;\r\n default:\r\n console.log('2_d')\r\n this.mirrorGrid[j], [k] = [0]; //\r\n break;\r\n }\r\n break;\r\n }\r\n }\r\n\r\n }\r\n //copy\r\n for (var x = 0; x < this.gridHeight; x++) { //iterate through rows\r\n for (var y = 0; y < this.gridWidth; y++) { //iterate through columns\r\n this.theGrid[x],[y] = this.mirrorGrid[x],[y]\r\n console.log( this.mirrorGrid[x],[y])\r\n\r\n }\r\n }\r\n }\r\n}","__index":{"obj":0},"__func":"constructor","__args":[100]}u
https://whatsonchain.com/tx/fd3ca3beeef0e97d1e979fce764f17bf9eda898f69a2fafaa43e725798348203