MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / tick

Method tick

projects/Neurons/main.py:63–85  ·  view source on GitHub ↗

Randomly kill or move all Neurons.

(self)

Source from the content-addressed store, hash-verified

61 self._grid[y][x] = Neuron()
62
63 def tick(self) -> None:
64 """Randomly kill or move all Neurons."""
65 for neuron_data in self.neurons:
66 neuron = neuron_data[0]
67 x, y = neuron_data[1]
68
69 if random.randint(1, 100) <= Neuron.CHANCE_OF_DEATH:
70 self._grid[y][x] = Empty()
71 continue
72
73 direction = random.choice(list(Direction))
74 if direction == Direction.UP:
75 y -= 1
76 elif direction == Direction.RIGHT:
77 x += 1
78 elif direction == Direction.DOWN:
79 y += 1
80 elif direction == Direction.LEFT:
81 x -= 1
82 try:
83 self._grid[y][x] = Neuron()
84 except IndexError:
85 pass
86
87
88def main() -> None:

Callers 8

mainFunction · 0.95
runMethod · 0.45
main.pyFile · 0.45
tesla.pyFile · 0.45
executeMethod · 0.45
mainFunction · 0.45
main.pyFile · 0.45
play_stepMethod · 0.45

Calls 2

EmptyClass · 0.70
NeuronClass · 0.70

Tested by

no test coverage detected