Skip to content

Commit 9c63153

Browse files
Merge pull request #2731 from avinashkranjan/deepsource-transform-5e0af933
format code with autopep8
2 parents f7ca6cc + 7b6f44e commit 9c63153

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Cellular Automaton Wars/cellular_automation_wars.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@
1010
1: lambda neighbors, energy: (sum(neighbors) - energy) % 2
1111
}
1212

13+
1314
def initialize_grid():
1415
grid = [0] * GRID_SIZE
1516
for _ in range(NUM_ORGANISMS):
1617
organism_position = random.randint(0, GRID_SIZE - 1)
17-
grid[organism_position] = random.randint(1, 5)
18+
grid[organism_position] = random.randint(1, 5)
1819
for _ in range(NUM_RESOURCES):
1920
resource_position = random.randint(0, GRID_SIZE - 1)
2021
resource_value = random.randint(1, 5)
21-
grid[resource_position] = -resource_value
22+
grid[resource_position] = -resource_value
2223
return grid
2324

25+
2426
def get_neighbors(grid, index):
2527
neighbors = []
2628
if index > 0:
@@ -29,6 +31,7 @@ def get_neighbors(grid, index):
2931
neighbors.append(grid[index + 1])
3032
return neighbors
3133

34+
3235
def apply_rule(grid, index):
3336
cell_state = grid[index]
3437
neighbors = get_neighbors(grid, index)
@@ -38,11 +41,13 @@ def apply_rule(grid, index):
3841
if energy >= ENERGY_THRESHOLD and grid.count(0) > 1:
3942
empty_spots = [i for i in range(GRID_SIZE) if grid[i] == 0]
4043
new_organism_position = random.choice(empty_spots)
41-
grid[new_organism_position] = energy // 2 # New organism created through reproduction.
44+
# New organism created through reproduction.
45+
grid[new_organism_position] = energy // 2
4246
grid[index] = new_state
4347
elif cell_state < 0: # If the cell represents a resource.
4448
grid[index] = 0
4549

50+
4651
def run_simulation(grid, num_iterations):
4752
for _ in range(num_iterations):
4853
new_grid = grid.copy()
@@ -51,6 +56,7 @@ def run_simulation(grid, num_iterations):
5156
grid = new_grid
5257
return grid
5358

59+
5460
def display_grid(grid):
5561
for cell in grid:
5662
if cell == 0:
@@ -61,6 +67,7 @@ def display_grid(grid):
6167
print(abs(cell), end=' ')
6268
print()
6369

70+
6471
def main():
6572
grid = initialize_grid()
6673
display_grid(grid)
@@ -71,5 +78,6 @@ def main():
7178
print("\nSimulation Results:")
7279
display_grid(grid)
7380

81+
7482
if __name__ == "__main__":
7583
main()

0 commit comments

Comments
 (0)