def test_allies_in_range_melee_weapon(self): points_to_elevation = { Point(1, 0): -3, Point(0, 1): 4, Point(1, 1): 0, Point(2, 1): -4, Point(1, 2): 3 } tiles = [ Tile(elevation=elevation, point=point) for point, elevation in points_to_elevation.items() ] the_map = Map(3, 3, tiles) origin, below, above = self.a_units far_below = Soldier() far_above = Soldier() self.team_a.add_player(far_above) self.team_a.add_player(far_below) origin.equip_weapon(MeleeWeapon(10, 10, 10, 10)) the_map.place_unit(origin, Point(1, 1)) the_map.place_unit(below, Point(1, 0)) the_map.place_unit(above, Point(1, 2)) the_map.place_unit(far_above, Point(0, 1)) the_map.place_unit(far_below, Point(2, 1)) tf = TargetFinder(the_map, [self.team_a, self.team_b]) answer = tf.allies_in_range(origin) expected = {below: (1, 1), above: (1, -1)} self.assertEqual(answer, expected)
def test_allies_in_range_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] test_unit.equip_weapon(RangedWeapon(10, 10, 10, 10)) teams = [self.team_a, self.team_b] test = TargetFinder(self.map, teams) answer = test.allies_in_range(test_unit) self.assertEqual(answer, {})
def test_allies_in_range_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] test_unit.equip_weapon(RangedWeapon(10, 10, 10, 10)) teams = [self.team_a, self.team_b] test = TargetFinder(self.map, teams) answer = test.allies_in_range(test_unit) expected = {self.a_units[1]: (2, 0), self.a_units[2]: (4, 0)} self.assertEqual(answer, expected)
def test_allies_in_range_by_weapon_range(self): origin, in_range, out_of_range = self.a_units for weapon_range in range(1, 5): self.map.remove_all_units() self.map.place_unit(origin, Point(0, 0)) self.map.place_unit(in_range, Point(weapon_range, 0)) self.map.place_unit(out_of_range, Point(weapon_range + 1, 0)) tf = TargetFinder(self.map, [self.team_a, self.team_b]) origin.equip_weapon(RangedWeapon(1, 1, weapon_range, 1)) answer = tf.allies_in_range(origin) expected = { in_range: (weapon_range, 0), } self.assertEqual(answer, expected)
def test_allies_in_range_advantage(self): points_to_elevation = {Point(0, 0): 0, Point(1, 0): -1, Point(2, 0): 1} tiles = [ Tile(elevation=elevation, point=point) for point, elevation in points_to_elevation.items() ] the_map = Map(3, 1, tiles) origin, below, above = self.a_units origin.equip_weapon(RangedWeapon(10, 10, 10, 10)) the_map.place_unit(origin, Point(0, 0)) the_map.place_unit(below, Point(1, 0)) the_map.place_unit(above, Point(2, 0)) tf = TargetFinder(the_map, [self.team_a, self.team_b]) answer = tf.allies_in_range(origin) expected = {below: (1, 1), above: (2, -1)} self.assertEqual(answer, expected)
def test_allies_in_range_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_range, out_of_sight = self.a_units origin.equip_weapon(RangedWeapon(10, 10, 10, 10)) the_map.place_unit(origin, Point(0, 0)) the_map.place_unit(in_range, 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_range(origin) expected = { in_range: (1, -1), } self.assertEqual(answer, expected)