diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index 4e5f9ff..ad0e3b3 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -194,7 +194,7 @@ class Map: self.add_entity(dictclasses[entisave["type"]](**entisave)) @staticmethod - def neighbourhood(grid, y, x, large=False): + def neighbourhood(grid, y, x, large=False, oob=False): """ Returns up to 8 nearby coordinates, in a 3x3 square around the input coordinate if large is set to True, or in a 5-square cross by default. Does not return coordinates if they are out @@ -203,12 +203,12 @@ class Map: height, width = len(grid), len(grid[0]) neighbours = [] if large: - dyxs = product([-1, 0, 1], [-1, 0, 1]) + dyxs = [[dy, dx] for dy, dx in product([-1, 0, 1], [-1, 0, 1])] dyxs = dyxs[:5] + dyxs[6:] else: dyxs = [[0, -1], [0, 1], [-1, 0], [1, 0]] for dy, dx in dyxs: - if 0 <= y+dy < height and 0 <= x+dx < width: + if oob or (0 <= y+dy < height and 0 <= x+dx < width): neighbours.append([y+dy, x+dx]) return neighbours diff --git a/squirrelbattle/mapgeneration/broguelike.py b/squirrelbattle/mapgeneration/broguelike.py index b986b8f..96c7153 100644 --- a/squirrelbattle/mapgeneration/broguelike.py +++ b/squirrelbattle/mapgeneration/broguelike.py @@ -39,9 +39,16 @@ class Generator: for rx in range(rw): if room[ry][rx] == Tile.FLOOR: ly, lx = y + ry - door_y, x + rx - door_x + # tile must be in bounds and empty if not(0 <= ly < lh and 0 <= lx < lw) or \ level[ly][lx] == Tile.FLOOR: return False + # so do all neighbouring tiles bc we may + # need to place walls there eventually + for ny, nx in Map.neighbourhood(level, ly, lx, large=True, oob=True): + if not(0 <= ny < lh and 0 <= nx < lw) or \ + level[ny][nx] != Tile.EMPTY: + return False return True @staticmethod