Function
__judge_point
(pt: bool, neighbours: list[list[bool]])
Source from the content-addressed store, hash-verified
| 76 | |
| 77 | |
| 78 | def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool: |
| 79 | dead = 0 |
| 80 | alive = 0 |
| 81 | # finding dead or alive neighbours count. |
| 82 | for i in neighbours: |
| 83 | for status in i: |
| 84 | if status: |
| 85 | alive += 1 |
| 86 | else: |
| 87 | dead += 1 |
| 88 | |
| 89 | # handling duplicate entry for focus pt. |
| 90 | if pt: |
| 91 | alive -= 1 |
| 92 | else: |
| 93 | dead -= 1 |
| 94 | |
| 95 | # running the rules of game here. |
| 96 | state = pt |
| 97 | if pt: |
| 98 | if alive < 2: |
| 99 | state = False |
| 100 | elif alive in {2, 3}: |
| 101 | state = True |
| 102 | elif alive > 3: |
| 103 | state = False |
| 104 | elif alive == 3: |
| 105 | state = True |
| 106 | |
| 107 | return state |
| 108 | |
| 109 | |
| 110 | if __name__ == "__main__": |
Tested by
no test coverage detected