daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function process(matrix) { //creates the next generation
  2.  
  3. var neighbors = 0,
  4.     position = '',
  5.     nextgen = new Array(8); //the matrix has 8 rows
  6.     for (i = 1; i <= 8; i++) {
  7.         nextgen[i] = new Array(8);
  8.         for (j = 1; j <= 8; j++) {
  9.             neighbors = neighbors(matrix, i, j);
  10.  
  11.             //Game Rules
  12.                 if (neighbors < 2) {nextgen[i][j] = 0;
  13.                 } else if (neighbors == 2) {nextgen[i][j] = 1;
  14.                 } else if (neighbors <= 3) {nextgen[i][j] = nextgen[i][j];
  15.                 } else {nextgen[i][j] = 0;}
  16.         }
  17.     }
  18.     return nextgen;
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top