2020-12-11 17:59:07 +00:00
|
|
|
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
import unittest
|
2021-01-08 15:21:16 +00:00
|
|
|
from random import randint
|
2020-12-11 17:59:07 +00:00
|
|
|
|
|
|
|
from squirrelbattle.interfaces import Map, Tile
|
2021-01-08 15:16:42 +00:00
|
|
|
from squirrelbattle.mapgeneration import broguelike
|
2021-01-08 15:11:17 +00:00
|
|
|
|
|
|
|
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()
|
2021-01-08 15:21:16 +00:00
|
|
|
if grid[y][x].can_walk():
|
|
|
|
grid[y][x] = Tile.WALL
|
2021-01-08 15:11:17 +00:00
|
|
|
queue += Map.neighbourhood(grid, y, x)
|
2021-01-08 15:21:16 +00:00
|
|
|
return not(any([any([t.can_walk() for t in l]) for l in grid]))
|
2020-12-11 17:59:07 +00:00
|
|
|
|
2021-01-08 15:11:17 +00:00
|
|
|
class TestBroguelike(unittest.TestCase):
|
|
|
|
def setUp(self) -> None:
|
|
|
|
self.generator = broguelike.Generator()
|
2021-01-08 15:16:42 +00:00
|
|
|
|
2021-01-08 15:11:17 +00:00
|
|
|
def test_connexity(self) -> None:
|
|
|
|
m = self.generator.run()
|
2021-01-08 15:21:16 +00:00
|
|
|
self.assertTrue(is_connex(m.tiles))
|