@@ -8,17 +8,10 @@ The Game of Life is a cellular automaton devised by the British mathematician Jo
8
8
(example adapted from https://github.com/TheAlgorithms/Python/blob/master/cellular_automata/conways_game_of_life.py )
9
9
*/
10
10
11
- /*
12
- * Doctests
13
- *
14
- * > newGeneration([[0, 1, 0], [0, 1, 0], [0, 1, 0]])
15
- * [ [ 0, 0, 0 ], [ 1, 1, 1 ], [ 0, 0, 0 ] ]
16
- */
17
-
18
- /*
19
- * Generates the next generation for a given state of Conway's Game of Life.
20
- */
21
- function newGeneration ( cells ) {
11
+ /**
12
+ * Generates the next generation for a given state of Conway's Game of Life.
13
+ */
14
+ export function newGeneration ( cells ) {
22
15
const nextGeneration = [ ]
23
16
for ( let i = 0 ; i < cells . length ; i ++ ) {
24
17
const nextGenerationRow = [ ]
@@ -46,45 +39,3 @@ function newGeneration (cells) {
46
39
}
47
40
return nextGeneration
48
41
}
49
-
50
- /*
51
- * utility function to display a series of generations in the console
52
- */
53
- async function animate ( cells , steps ) {
54
- /*
55
- * utility function to print one frame
56
- */
57
- function printCells ( cells ) {
58
- console . clear ( )
59
- for ( let i = 0 ; i < cells . length ; i ++ ) {
60
- let line = ''
61
- for ( let j = 0 ; j < cells [ i ] . length ; j ++ ) {
62
- if ( cells [ i ] [ j ] === 1 ) line += '\u2022'
63
- else line += ' '
64
- }
65
- console . log ( line )
66
- }
67
- }
68
-
69
- printCells ( cells )
70
-
71
- for ( let i = 0 ; i < steps ; i ++ ) {
72
- await new Promise ( resolve => setTimeout ( resolve , 250 ) ) // sleep
73
- cells = newGeneration ( cells )
74
- printCells ( cells )
75
- }
76
- }
77
-
78
- // Define glider example
79
- const glider = [
80
- [ 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
81
- [ 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 ] ,
82
- [ 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 ] ,
83
- [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
84
- [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
85
- [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
86
- [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
87
- [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]
88
- ]
89
-
90
- animate ( glider , 16 )
0 commit comments