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]])
| 53 | |
| 54 | |
| 55 | def 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 | |
| 78 | def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool: |
no test coverage detected