-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrulesoflife.txt
62 lines (49 loc) · 1.21 KB
/
rulesoflife.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
====
xxx
xox
oox
====
(x,y)
====
xox
xox
oxo
====
neighbourOffsets = [[1,0], [1,1], [0,1], [-1,1], [-1,0], [-1,-1], [0,-1], [1,-1]]
grid = [ 'xxx', 'xox', 'oox']
getNeighbourCoordinates(cell (array))]
use neighbourOffsets
return arrayOfNeighbourCoordinates
getValueOfCell(cell (array), grid (2d array))
return value
deadOrAlive(cell (array), grid (2d array))
aliveNeighbours = 0
getNeighbours
loop over neighbours
getValueOfCell(neighbourCell)
if value alive
aliveNeighbours + 1
use current cell to determine if it lives on
if alive
return false if aliveNeighbours < 2
return true if aliveNeighbours >= 2 && <= 3
return false if > 3
else if dead
return true if aliveNeighbours == 3
return false
calculateNextState(grid)
make a copy of current as nextGrid
loop over grid
get value of each cell
get its neighbours
calculate if its dead or alive
update nextGrid with cell value
return nextGrid
breed(grid)
set a timeout for
calculate next state of grid
print grid
if not isOver(grid)
run breed
isOver(grid)
return true/false