def test_nearby_tiles(self): map = basic_map.TileMap(10, 10) map2 = basic_map.TileMap(10, 10) tile = map.getTile(3, 4) tile.map_transition = map2 nearby = map.getNearbyTiles(tile) self.assertTrue(map2.getTile(3, 4) in nearby) tile2 = map.getTile(0, 0) nearby2 = map2.getNearbyTiles(tile) self.assertTrue(map2.getTile(0, 9) in nearby2)
def test_cellular_automata_ordinary(self): b = [3] s = [2, 3] map = basic_map.TileMap(9, 9) gen = ca.CellularAutomataGenerator(b, s, map) gen.clearSimulation(ca.DEAD) living_tiles = [ map.getTile(3, 3), map.getTile(2, 3), map.getTile(4, 3) ] for tile in living_tiles: tile._state = ca.ALIVE gen.run() self.assertTrue(map.getTile(3, 3)._state == ca.ALIVE) self.assertTrue(map.getTile(3, 4)._state == ca.ALIVE) self.assertTrue(map.getTile(3, 2)._state == ca.ALIVE) self.assertTrue(map.getTile(4, 3)._state == ca.DEAD) self.assertTrue(map.getTile(2, 3)._state == ca.DEAD) gen.run(2) #should end with the same state it started in. self.assertTrue(map.getTile(3, 3)._state == ca.ALIVE) self.assertTrue(map.getTile(3, 4)._state == ca.ALIVE) self.assertTrue(map.getTile(3, 2)._state == ca.ALIVE) self.assertTrue(map.getTile(4, 3)._state == ca.DEAD) self.assertTrue(map.getTile(2, 3)._state == ca.DEAD)
def test_randomize_function(self): map = basic_map.TileMap(10, 10) gen = ca.CellularAutomataGenerator([], [], map) gen.randomizeInitialConditions(.6) self.assertTrue( len([ tile for tile in map.getAllTiles() if tile._state == ca.ALIVE ]) == 60)
def __init__(self, b : list, s : list, initial_map : basic_map.TileMap = basic_map.TileMap(50,50),): self.b = b self.s = s self.initial_map = initial_map self.initial_map.IMPASSIBLE_TILE._state = DEAD #If we're not wrapping, treat the impassible tile as dead. (If we are, we'll never see it.) self.max_x = initial_map.max_x self.max_y = initial_map.max_y self.clearSimulation(DEAD)
def test_cellular_automata_extremes(self): b = [x for x in range(0, 20)] s = [] map = basic_map.TileMap(5, 5) gen = ca.CellularAutomataGenerator(b, s, map) gen.clearSimulation(ca.DEAD) gen.run() for tile in map.getAllTiles(): self.assertTrue(tile._state == ca.ALIVE) gen.run() for tile in map.getAllTiles(): self.assertTrue(tile._state == ca.DEAD) gen.b = [] gen.run() for tile in map.getAllTiles(): self.assertTrue(tile._state == ca.DEAD) state_to_terrain = {ca.DEAD: "rock", ca.ALIVE: "floor"} gen.finalizeMap(state_to_terrain) for tile in map.getAllTiles(): self.assertTrue(tile.terrain == "rock") gen.printSimulation()