-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.py
39 lines (28 loc) · 1.24 KB
/
Board.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
29
30
31
32
33
34
35
36
37
38
39
import numpy as np
from common import EntityType
from typing import List, Tuple, Any
class Board:
cells: np.ndarray # EntityType ndarray
def __init__(self, boardsize: Tuple[int, int]):
self.cells = np.empty(boardsize, dtype=EntityType)
def getEmptyCells(self) -> List[Tuple[int, int]]:
return list(zip(*np.where(self.cells == None)))
def occupyCell(self, cell: Tuple[int, int], entitytype: EntityType) -> None:
if cell[0] < 0 or cell[1] < 0:
raise IndexError("There are no negative indices.")
self.cells[cell] = entitytype
def occupyCells(self, cells: List[Tuple[int, int]], entitytype: EntityType) -> None:
for cell in cells:
if cell[0] < 0 or cell[1] < 0:
raise IndexError("There are no negative indices.")
self.cells[cell] = entitytype
def abandonCell(self, cell: Tuple[int, int]) -> None:
self.cells[cell] = None
def getCellContent(self, cell: Tuple[int, int]) -> EntityType:
return self.cells[cell]
def isCellInsideBoard(self, cell: Tuple[int, int]) -> bool:
try:
self.cells[cell]
except IndexError:
return False
return True