-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcell.py
More file actions
30 lines (25 loc) · 875 Bytes
/
cell.py
File metadata and controls
30 lines (25 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# cell.py
class Cell:
"""
Represents a cell in the grid.
Utilizes Encapsulation design pattern to bundle the cell's state and position.
"""
def __init__(self, state, position):
"""
Initialize a cell with a state and position.
Parameters:
state (int): The initial state of the cell, 0 for dead and 1 for alive.
position (tuple): The (x, y) position of the cell in the grid.
"""
self.state = state
self.position = position
def flip_state(self):
"""
Flip the cell's state from dead to alive or vice versa.
"""
self.state = 1 - self.state
if __name__ == "__main__":
example_cell = Cell(state=0, position=(0, 0))
print(f"Initial state: {example_cell.__dict__}")
example_cell.flip_state()
print(f"State after flip: {example_cell.__dict__}")