Esempio n. 1
0
    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})
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)