simples wfc, funktioniert noch nicht immer
This commit is contained in:
14
src/net.py
14
src/net.py
@@ -13,14 +13,17 @@ class Grid:
|
||||
width: int
|
||||
height: int
|
||||
|
||||
def __init__(self, width: int, height: int) -> None:
|
||||
def __init__(self, width: int, height: int, specific: int | None = None) -> None:
|
||||
self.height = height
|
||||
self.width = width
|
||||
if width != height or width not in [3, 5, 7, 9, 11, 13]:
|
||||
raise ValueError("Feldgrösse nicht erlaubt")
|
||||
with open(f"descriptions/{width}x{height}.txt") as f:
|
||||
lines = f.readlines()
|
||||
selected = choice(lines).strip()
|
||||
if specific:
|
||||
selected = lines[specific].strip()
|
||||
else:
|
||||
selected = choice(lines).strip()
|
||||
self.pieces = parse_description(selected)
|
||||
|
||||
def neighbors(self, x: int, y: int) -> list[Coordinate]:
|
||||
@@ -71,8 +74,8 @@ class NetGame:
|
||||
width: int
|
||||
height: int
|
||||
|
||||
def __init__(self, width: int, height: int) -> None:
|
||||
self._grid = Grid(width, height)
|
||||
def __init__(self, width: int, height: int, specific: int | None = None) -> None:
|
||||
self._grid = Grid(width, height, specific)
|
||||
self.width = width
|
||||
self.height = height
|
||||
|
||||
@@ -94,5 +97,8 @@ class NetGame:
|
||||
def set_direction(self, x: int, y: int, dir: Direction) -> None:
|
||||
self._grid.pieces[x][y].direction = dir
|
||||
|
||||
def neighbors(self, x: int, y: int) -> list[Coordinate]:
|
||||
return self._grid.neighbors(x, y)
|
||||
|
||||
def solved(self):
|
||||
return self._grid.solved()
|
||||
|
||||
Reference in New Issue
Block a user