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

Function __judge_point

cellular_automata/game_of_life.py:78–107  ·  view source on GitHub ↗
(pt: bool, neighbours: list[list[bool]])

Source from the content-addressed store, hash-verified

76
77
78def __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
110if __name__ == "__main__":

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected