Guest User

Untitled

a guest
Dec 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment