Update game_of_life.py (#4921)

* Update game_of_life.py

docstring error fix
delete no reason delete next_gen_canvas code(local variable)

* Update cellular_automata/game_of_life.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Minha, Jeong 2023-08-01 06:24:12 +09:00 committed by GitHub
parent 5cf34d901e
commit f8fe72dc37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,7 @@ Python:
- 3.5 - 3.5
Usage: Usage:
- $python3 game_o_life <canvas_size:int> - $python3 game_of_life <canvas_size:int>
Game-Of-Life Rules: Game-Of-Life Rules:
@ -52,7 +52,8 @@ def seed(canvas: list[list[bool]]) -> None:
def run(canvas: list[list[bool]]) -> list[list[bool]]: def run(canvas: list[list[bool]]) -> list[list[bool]]:
"""This function runs the rules of game through all points, and changes their """
This function runs the rules of game through all points, and changes their
status accordingly.(in the same canvas) status accordingly.(in the same canvas)
@Args: @Args:
-- --
@ -60,7 +61,7 @@ def run(canvas: list[list[bool]]) -> list[list[bool]]:
@returns: @returns:
-- --
None canvas of population after one step
""" """
current_canvas = np.array(canvas) current_canvas = np.array(canvas)
next_gen_canvas = np.array(create_canvas(current_canvas.shape[0])) next_gen_canvas = np.array(create_canvas(current_canvas.shape[0]))
@ -70,10 +71,7 @@ def run(canvas: list[list[bool]]) -> list[list[bool]]:
pt, current_canvas[r - 1 : r + 2, c - 1 : c + 2] pt, current_canvas[r - 1 : r + 2, c - 1 : c + 2]
) )
current_canvas = next_gen_canvas return next_gen_canvas.tolist()
del next_gen_canvas # cleaning memory as we move on.
return_canvas: list[list[bool]] = current_canvas.tolist()
return return_canvas
def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool: def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool: