Beispiel #1
0
    def test_allies_in_sight_by_sight_range(self):
        origin, in_sight, out_of_sight = self.a_units
        self.map.place_unit(origin, Point(0, 0))
        self.map.place_unit(in_sight, Point(10, 0))
        self.map.place_unit(out_of_sight, Point(11, 0))
        tf = TargetFinder(self.map, [self.team_a, self.team_b])

        answer = tf.allies_in_sight(origin)
        expected = {
            in_sight: 10,
        }
        self.assertEqual(answer, expected)

        self.map.remove_unit(Point(10, 0))
        self.map.remove_unit(Point(11, 0))
        self.map.place_unit(in_sight, Point(5, 5))
        self.map.place_unit(out_of_sight, Point(5, 6))
        answer = tf.allies_in_sight(origin)
        self.assertEqual(answer, expected)
Beispiel #2
0
    def test_allies_in_sight_no_allies(self):
        all_units = self.a_units[0:1] + self.b_units
        for index, unit in enumerate(all_units):
            self.map.place_unit(unit, Point(index, index))
        test_unit = all_units[0]

        teams = [self.team_a, self.team_b]
        test = TargetFinder(self.map, teams)
        answer = test.allies_in_sight(test_unit)
        self.assertEqual(answer, {})
Beispiel #3
0
    def test_allies_in_sight_answer_excludes_non_allies(self):
        all_units = self.a_units + self.b_units
        for index, unit in enumerate(all_units):
            self.map.place_unit(unit, Point(index, index))
        test_unit = all_units[0]
        self.assertEqual(test_unit.get_sight_range(), 10)

        teams = [self.team_a, self.team_b]
        test = TargetFinder(self.map, teams)
        answer = test.allies_in_sight(test_unit)
        expected = {self.a_units[1]: 2, self.a_units[2]: 4}
        self.assertEqual(answer, expected)
Beispiel #4
0
    def test_allies_in_sight_different_sight_range(self):
        class NewSoldier(Soldier):
            def get_sight_range(self):
                return 3

        short_sighted = NewSoldier()
        self.team_a.add_player(short_sighted)

        in_sight, also_in_sight, out_of_sight = self.a_units
        self.map.place_unit(short_sighted, Point(0, 0))
        self.map.place_unit(in_sight, Point(3, 0))
        self.map.place_unit(also_in_sight, Point(2, 1))
        self.map.place_unit(out_of_sight, Point(4, 0))
        tf = TargetFinder(self.map, [self.team_a, self.team_b])

        answer = tf.allies_in_sight(short_sighted)
        expected = {in_sight: 3, also_in_sight: 3}
        self.assertEqual(answer, expected)
Beispiel #5
0
    def test_allies_in_sight_by_obstructed_view(self):
        points_to_elevation = {Point(0, 0): 0, Point(1, 0): 1, Point(2, 0): 0}
        tiles = [
            Tile(elevation=elevation, point=point)
            for point, elevation in points_to_elevation.items()
        ]
        the_map = Map(3, 1, tiles)

        origin, in_sight, out_of_sight = self.a_units
        the_map.place_unit(origin, Point(0, 0))
        the_map.place_unit(in_sight, Point(1, 0))
        the_map.place_unit(out_of_sight, Point(2, 0))

        tf = TargetFinder(the_map, [self.team_a, self.team_b])

        answer = tf.allies_in_sight(origin)
        expected = {
            in_sight: 1,
        }
        self.assertEqual(answer, expected)