def test_relocate_item_map_full(self): # fmt: off gm = create_map_with([[E, W], [W, W]]) # fmt: on gs = GameState(gm, []) black_hole_pos = Position(1, 1) gm.set_tile(black_hole_pos, GameMap.BLACK_HOLE) self.assertTrue(gm.is_black_hole(black_hole_pos)) new_black_hole_pos = gs.relocate_item(black_hole_pos) self.assertEqual(None, new_black_hole_pos)
def test_relocate_item(self): # fmt: off gm = create_map_with([[1, E, E], [E, W, E], [E, E, E]]) # fmt: on ps = PlayerState(id=1, name="dummy", game_map=gm, position=Position(1, 1)) gs = GameState(gm, [ps]) ps.position = Position(3, 1) ps.tail = [Position(2, 1), Position(3, 1)] asteroids_pos = Position(2, 2) self.assertTrue(gm.is_asteroids(asteroids_pos)) planet_pos = Position(3, 3) gm.set_tile(planet_pos, GameMap.PLANET) self.assertTrue(gm.is_planet(planet_pos)) black_hole_pos = Position(1, 2) gm.set_tile(black_hole_pos, GameMap.BLACK_HOLE) self.assertTrue(gm.is_black_hole(black_hole_pos)) blitzium_pos = Position(1, 3) gm.set_tile(blitzium_pos, GameMap.BLITZIUM) self.assertTrue(gm.is_blitzium(blitzium_pos)) # Cannot relocate asteroids and planets with self.assertRaises(Exception): gs.relocate_item(asteroids_pos) with self.assertRaises(Exception): gs.relocate_item(planet_pos) # relocate black holes and blitziums for i in range(30): new_black_hole_pos = gs.relocate_item(black_hole_pos) self.assertTrue(new_black_hole_pos not in list( {asteroids_pos, planet_pos, black_hole_pos, blitzium_pos}) + ps.tail) black_hole_pos = new_black_hole_pos new_blitzium_pos = gs.relocate_item(blitzium_pos) self.assertTrue(new_blitzium_pos != blitzium_pos)