def test_get_attackers(self): points_to_elevation = { Point(0, 0): 0, Point(1, 0): 5, Point(2, 0): 0, Point(0, 1): 1, Point(1, 1): 1, Point(2, 1): 2, Point(0, 2): 2, Point(1, 2): 3, Point(2, 2): 3 } tiles = [ Tile(elevation=elevation, point=point) for point, elevation in points_to_elevation.items() ] the_map = Map(3, 3, tiles) listener = PerimeterListener(the_map) melee_pt = Point(1, 1) ranged_pt = Point(0, 0) listener.set_perimeter(self.melee, melee_pt) listener.set_perimeter(self.ranged, ranged_pt) self.assertEqual(listener.get_attackers(Point(2, 2)), set()) self.assertEqual(listener.get_attackers(Point(0, 1)), {self.ranged, self.melee}) self.assertEqual(listener.get_attackers(Point(0, 2)), {self.ranged}) self.assertEqual(listener.get_attackers(Point(1, 2)), {self.melee})
def __init__(self, map_: Map, team_1: Team, team_2: Team): self._map = map_ self._team_1 = team_1 self._team_2 = team_2 self._pm = PerimeterListener(self._map) self._mc = MovementCalculator(self._map) self._rf = RangeFinder(self._map) self._unmoved_units = []
def test_rm_perimeter_one_unit(self): points_to_elevation = { Point(0, 0): 0, Point(1, 0): 5, Point(2, 0): 0, Point(0, 1): 1, Point(1, 1): 1, Point(2, 1): 2, Point(0, 2): 2, Point(1, 2): 3, Point(2, 2): 3 } tiles = [ Tile(elevation=elevation, point=point) for point, elevation in points_to_elevation.items() ] the_map = Map(3, 3, tiles) listener = PerimeterListener(the_map) melee_pt = Point(1, 1) listener.set_perimeter(self.melee, melee_pt) empty = {pt: set() for pt in points_to_elevation} non_empty = {pt: set() for pt in points_to_elevation} non_empty[Point(0, 1)] = {self.melee} non_empty[Point(2, 1)] = {self.melee} non_empty[Point(1, 2)] = {self.melee} self.assertEqual(listener._watchers_at_point, non_empty) listener.rm_perimeter(self.melee) self.assertEqual(listener._watchers_at_point, empty)
def test_set_perimeter_two_units(self): points_to_elevation = { Point(0, 0): 0, Point(1, 0): 5, Point(2, 0): 0, Point(0, 1): 1, Point(1, 1): 1, Point(2, 1): 2, Point(0, 2): 2, Point(1, 2): 3, Point(2, 2): 3 } tiles = [ Tile(elevation=elevation, point=point) for point, elevation in points_to_elevation.items() ] the_map = Map(3, 3, tiles) listener = PerimeterListener(the_map) melee_pt = Point(1, 1) ranged_pt = Point(0, 0) listener.set_perimeter(self.melee, melee_pt) listener.set_perimeter(self.ranged, ranged_pt) expected = {key: set() for key in points_to_elevation} expected[Point(0, 1)] = {self.ranged, self.melee} expected[Point(1, 0)] = {self.ranged} expected[Point(0, 2)] = {self.ranged} expected[Point(1, 1)] = {self.ranged} expected[Point(2, 1)] = {self.melee} expected[Point(1, 2)] = {self.melee} self.assertEqual(listener._watchers_at_point, expected)
def test_set_perimeter_ranged(self): points_to_elevation = { Point(0, 0): 0, Point(1, 0): 5, Point(2, 0): 0, Point(0, 1): 1, Point(1, 1): 1, Point(2, 1): 2, Point(0, 2): 2, Point(1, 2): 3, Point(2, 2): 3 } tiles = [ Tile(elevation=elevation, point=point) for point, elevation in points_to_elevation.items() ] the_map = Map(3, 3, tiles) origin = Point(0, 0) expected_ranges = { 0: [(Point(0, 0), 0)], 1: [(Point(1, 0), -1), (Point(0, 1), -1)], 2: [(Point(1, 1), -1), (Point(0, 2), -1)] } self.assertEqual( RangeFinder(map_=the_map).get_attack_ranges_ranged(origin, range_=2), expected_ranges) listener = PerimeterListener(the_map) listener.set_perimeter(self.ranged, origin) expected = {key: set() for key in points_to_elevation} expected[Point(0, 1)] = {self.ranged} expected[Point(1, 0)] = {self.ranged} expected[Point(0, 2)] = {self.ranged} expected[Point(1, 1)] = {self.ranged} self.assertEqual(listener._watchers_at_point, expected)
def test_init_creates_empty_table_with_unique_sets(self): points = [ Point(0, 0), Point(1, 0), Point(2, 0), Point(0, 1), Point(1, 1), Point(2, 1) ] tiles = [Tile(point=pt) for pt in points] map_ = Map(3, 2, tiles) listener = PerimeterListener(map_) expected = {pt: set() for pt in points} self.assertEqual(listener._watchers_at_point, expected) listener._watchers_at_point[Point(0, 0)].add(1) self.assertEqual(listener._watchers_at_point[Point(1, 0)], set())