MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / run

Function run

cellular_automata/game_of_life.py:55–75  ·  view source on GitHub ↗

This function runs the rules of game through all points, and changes their status accordingly.(in the same canvas) @Args: -- canvas : canvas of population to run the rules on. @returns: -- canvas of population after one step

(canvas: list[list[bool]])

Source from the content-addressed store, hash-verified

53
54
55def run(canvas: list[list[bool]]) -> list[list[bool]]:
56 """
57 This function runs the rules of game through all points, and changes their
58 status accordingly.(in the same canvas)
59 @Args:
60 --
61 canvas : canvas of population to run the rules on.
62
63 @returns:
64 --
65 canvas of population after one step
66 """
67 current_canvas = np.array(canvas)
68 next_gen_canvas = np.array(create_canvas(current_canvas.shape[0]))
69 for r, row in enumerate(current_canvas):
70 for c, pt in enumerate(row):
71 next_gen_canvas[r][c] = __judge_point(
72 pt, current_canvas[r - 1 : r + 2, c - 1 : c + 2]
73 )
74
75 return next_gen_canvas.tolist()
76
77
78def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool:

Callers 1

game_of_life.pyFile · 0.70

Calls 2

create_canvasFunction · 0.85
__judge_pointFunction · 0.85

Tested by

no test coverage detected