Linting
This commit is contained in:
@ -3,27 +3,29 @@
|
||||
|
||||
import unittest
|
||||
from random import randint
|
||||
from typing import List
|
||||
|
||||
from squirrelbattle.interfaces import Map, Tile
|
||||
from squirrelbattle.mapgeneration import broguelike
|
||||
|
||||
def is_connex(grid):
|
||||
h, w = len(grid), len(grid[0])
|
||||
y, x = randint(0, h-1), randint(0, w-1)
|
||||
while not(grid[y][x].can_walk()):
|
||||
y, x = randint(0, h-1), randint(0, w-1)
|
||||
queue = Map.neighbourhood(grid, y, x)
|
||||
while queue != []:
|
||||
y, x = queue.pop()
|
||||
if grid[y][x].can_walk():
|
||||
grid[y][x] = Tile.WALL
|
||||
queue += Map.neighbourhood(grid, y, x)
|
||||
return not(any([any([t.can_walk() for t in l]) for l in grid]))
|
||||
|
||||
class TestBroguelike(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.generator = broguelike.Generator()
|
||||
|
||||
def is_connex(self, grid: List[List[Tile]]) -> bool:
|
||||
h, w = len(grid), len(grid[0])
|
||||
y, x = randint(0, h - 1), randint(0, w - 1)
|
||||
while not (grid[y][x].can_walk()):
|
||||
y, x = randint(0, h - 1), randint(0, w - 1)
|
||||
queue = Map.neighbourhood(grid, y, x)
|
||||
while queue:
|
||||
y, x = queue.pop()
|
||||
if grid[y][x].can_walk():
|
||||
grid[y][x] = Tile.WALL
|
||||
queue += Map.neighbourhood(grid, y, x)
|
||||
return not any([t.can_walk() for row in grid for t in row])
|
||||
|
||||
def test_connexity(self) -> None:
|
||||
m = self.generator.run()
|
||||
self.assertTrue(is_connex(m.tiles))
|
||||
self.assertTrue(self.is_connex(m.tiles))
|
||||
|
Reference in New Issue
Block a user