-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid_2d.py
29 lines (24 loc) · 884 Bytes
/
grid_2d.py
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
from typing import Any
class Grid2D:
def __init__(self, width: int, height: int, initial_value: Any):
self.width = width
self.height = height
self.board = [initial_value] * (width * height)
def get_cell(self, row: int, column: int) -> Any | None:
if row >= 0 and row < self.height:
if column >=0 and column < self.width:
index = (row * self.width) + column
return self.board[index]
else:
return None
else:
return None
def set_cell(self, row: int, column: int, value: Any):
if row >= 0 and row < self.height:
if column >=0 and column < self.width:
index = (row * self.width) + column
self.board[index] = value
else:
return
else:
return