40
40
random .shuffle (choice )
41
41
42
42
43
- def create_canvas (size ) :
43
+ def create_canvas (size : int ) -> list [ list [ bool ]] :
44
44
canvas = [[False for i in range (size )] for j in range (size )]
45
45
return canvas
46
46
47
47
48
- def seed (canvas ) :
48
+ def seed (canvas : list [ list [ bool ]]) -> None :
49
49
for i , row in enumerate (canvas ):
50
50
for j , _ in enumerate (row ):
51
51
canvas [i ][j ] = bool (random .getrandbits (1 ))
52
52
53
53
54
- def run (canvas ) :
54
+ def run (canvas : list [ list [ bool ]]) -> list [ list [ bool ]] :
55
55
"""This function runs the rules of game through all points, and changes their
56
56
status accordingly.(in the same canvas)
57
57
@Args:
@@ -62,21 +62,22 @@ def run(canvas):
62
62
--
63
63
None
64
64
"""
65
- canvas = np .array (canvas )
66
- next_gen_canvas = np .array (create_canvas (canvas .shape [0 ]))
67
- for r , row in enumerate (canvas ):
65
+ current_canvas = np .array (canvas )
66
+ next_gen_canvas = np .array (create_canvas (current_canvas .shape [0 ]))
67
+ for r , row in enumerate (current_canvas ):
68
68
for c , pt in enumerate (row ):
69
69
# print(r-1,r+2,c-1,c+2)
70
70
next_gen_canvas [r ][c ] = __judge_point (
71
- pt , canvas [r - 1 : r + 2 , c - 1 : c + 2 ]
71
+ pt , current_canvas [r - 1 : r + 2 , c - 1 : c + 2 ]
72
72
)
73
73
74
- canvas = next_gen_canvas
74
+ current_canvas = next_gen_canvas
75
75
del next_gen_canvas # cleaning memory as we move on.
76
- return canvas .tolist ()
76
+ return_canvas : list [list [bool ]] = current_canvas .tolist ()
77
+ return return_canvas
77
78
78
79
79
- def __judge_point (pt , neighbours ) :
80
+ def __judge_point (pt : bool , neighbours : list [ list [ bool ]]) -> bool :
80
81
dead = 0
81
82
alive = 0
82
83
# finding dead or alive neighbours count.
0 commit comments