Exemplo n.º 1
0
 def test_modified_container(self):
     """Test to see if we can construct a container besides Bodyguard."""
     error_msg = "Container status should not be unique to Bodyguard."
     ant = ants.ThrowerAnt()
     ant.container = True
     ant.ant = None
     self.assertTrue(ant.can_contain(ants.ThrowerAnt()), error_msg)
Exemplo n.º 2
0
 def test_boost(self):
     thrower = ants.ThrowerAnt()
     fire = ants.FireAnt()
     front = ants.ThrowerAnt()
     thrower_armor = thrower.armor
     fire_armor = fire.armor
     princess_armor = self.princess_peach.armor
     thrower_damage = thrower.damage
     self.colony.places['tunnel_0_0'].add_insect(thrower)
     self.colony.places['tunnel_0_1'].add_insect(fire)
     self.colony.places['tunnel_0_2'].add_insect(self.princess_peach)
     self.colony.places['tunnel_0_3'].add_insect(front)
     thrower.action(
         self.colony)  # Armor boosted only after princess's action
     self.assertEqual(thrower_armor, thrower.armor,
                      "Armor boosted too early")
     self.princess_peach.action(self.colony)  # Princesses have normal armor
     self.assertEqual(self.princess_peach.armor, princess_armor,
                      "Princess armor incorrect")
     front.action(self.colony)  # Check if armor is boosted in front
     self.assertEqual(front.armor, thrower_armor + 1,
                      "Did not boost ant in front of princess correctly")
     fire.action(self.colony)  # Check if armor is boosted in back
     self.assertEqual(fire.armor, fire_armor + 1,
                      "Did not boost ant behind princess correctly")
     thrower.action(self.colony)  # Check if armor is boosted way back
     self.assertEqual(
         thrower.armor, thrower_armor + 1,
         "Did not boost ant behind ant behind princess correctly")
     self.assertEqual(thrower.damage, thrower_damage, "Damage incorrect")
Exemplo n.º 3
0
 def test_modified_container(self):
     #Test to see if we can construct a fake container
     error_msg = 'Container status should not be hard-coded'
     ant = ants.ThrowerAnt()
     ant.container = True
     ant.ant = None
     self.assertTrue(ant.can_contain(ants.ThrowerAnt()), error_msg)
Exemplo n.º 4
0
 def test_double(self):
     thrower = ants.ThrowerAnt()
     fire = ants.FireAnt()
     thrower_damage = ants.ThrowerAnt.damage
     fire_damage = ants.FireAnt.damage
     front = ants.ThrowerAnt()
     armor = 13
     bee = ants.Bee(armor)
     self.colony.places['tunnel_0_0'].add_insect(thrower)
     self.colony.places['tunnel_0_1'].add_insect(fire)
     self.colony.places['tunnel_0_2'].add_insect(TestProblem9.queen)
     self.colony.places['tunnel_0_3'].add_insect(front)
     self.colony.places['tunnel_0_4'].add_insect(bee)
     TestProblem9.queen.action(self.colony)
     armor -= thrower_damage  # Queen should always deal normal damage
     self.assertEqual(armor, bee.armor, "Queen damange incorrect")
     front.action(self.colony)
     armor -= thrower_damage  # Front is in front, not behind
     self.assertEqual(armor, bee.armor, "Front damange incorrect")
     bee.action(self.colony)  # Bee now in range of thrower
     thrower.action(self.colony)
     armor -= 2 * thrower_damage  # Thrower damage doubled
     self.assertEqual(armor, bee.armor, "Thrower damange incorrect")
     TestProblem9.queen.action(self.colony)
     armor -= thrower_damage
     self.assertEqual(armor, bee.armor, "Queen damange incorrect (2)")
     thrower.action(self.colony)
     armor -= 2 * thrower_damage  # Thrower damage doubled
     self.assertEqual(armor, bee.armor, "Thrower damange incorrect (2)")
     fire.place.add_insect(bee)  # Teleport the bee to the fire
     bee.action(self.colony)
     armor -= 2 * fire_damage  # Fire damage doubled
     self.assertEqual(armor, bee.armor, "Fire damange incorrect")
Exemplo n.º 5
0
def test():
    importlib.reload(ants)
    hive = ants.Hive(ants.AssaultPlan())
    dimensions = (2, 9)
    colony = ants.AntColony(None, hive, ants.ant_types(), ants.dry_layout,
                            dimensions)
    # Extensive damage doubling tests
    queen_tunnel, side_tunnel = [[
        colony.places['tunnel_{0}_{1}'.format(i, j)] for j in range(9)
    ] for i in range(2)]
    queen = ants.QueenAnt()
    queen_tunnel[7].add_insect(queen)
    # Turn 0
    thrower = ants.ThrowerAnt()
    fire = ants.FireAnt()
    ninja = ants.NinjaAnt()
    side = ants.ThrowerAnt()
    front = ants.NinjaAnt()
    queen_tunnel[0].add_insect(thrower)
    queen_tunnel[1].add_insect(fire)
    queen_tunnel[2].add_insect(ninja)
    queen_tunnel[8].add_insect(front)
    side_tunnel[0].add_insect(side)
    buffed_ants = [thrower, fire, ninja]
    old_dmgs = [ant.damage for ant in buffed_ants]
    queen.action(colony)
    for ant, dmg in zip(buffed_ants, old_dmgs):
        assert ant.damage == dmg * 2, "{0}'s damage is {1}, but should be {2}".format(
            ant, ant.damage, dmg * 2)
    for ant in [side, front]:
        assert ant.damage == dmg, "{0}'s damage is {1}, but should be {2}".format(
            ant, ant.damage, dmg)
    assert queen.damage == 1, 'QueenAnt damage was modified to {0}'.format(
        ant.damage)
    # Turn 1
    tank = ants.TankAnt()
    guard = ants.BodyguardAnt()
    queen_tank = ants.TankAnt()
    queen_tunnel[6].add_insect(tank)  # Not protecting an ant
    queen_tunnel[1].add_insect(guard)  # Guarding FireAnt
    queen_tunnel[7].add_insect(queen_tank)  # Guarding QueenAnt
    buffed_ants.extend([tank, guard])
    old_dmgs.extend([ant.damage for ant in [tank, guard, queen_tank]])
    queen.action(colony)
    for ant, dmg in zip(buffed_ants, old_dmgs):
        assert ant.damage == dmg * 2, "{0}'s damage is {1}, but should be {2}".format(
            ant, ant.damage, dmg * 2)

    # Turn 2
    thrower1 = ants.ThrowerAnt()
    thrower2 = ants.ThrowerAnt()
    queen_tunnel[6].add_insect(thrower1)  # Add thrower1 in TankAnt
    queen_tunnel[5].add_insect(thrower2)
    buffed_ants.extend([thrower1, thrower2])
    old_dmgs.extend([ant.damage for ant in [thrower1, thrower2]])
    queen.action(colony)
    for ant, dmg in zip(buffed_ants, old_dmgs):
        assert ant.damage == dmg * 2, "{0}'s damage is {1}, but should be {2}".format(
            ant, ant.damage, dmg * 2)
Exemplo n.º 6
0
 def test_multi_tunnel(self):
     thrower0 = ants.ThrowerAnt()
     thrower1 = ants.ThrowerAnt()
     thrower_armor = thrower0.armor
     self.colony.places['tunnel_0_0'].add_insect(thrower0)
     self.colony.places['tunnel_0_1'].add_insect(self.princess_peach)
     self.colony.places['tunnel_1_0'].add_insect(thrower1)
     self.princess_peach.action(self.colony)
     self.assertEqual(
         thrower0.armor, thrower_armor + 1,
         "Armor for ant in princess's tunnel incorrectly boosted")
     self.assertEqual(
         thrower1.armor, thrower_armor,
         "Armor for ant not in princess's tunnel incorrectly boosted")
Exemplo n.º 7
0
    def test_double(self):
        back = ants.ThrowerAnt()
        thrower_damage = ants.ThrowerAnt.damage
        fire_damage = ants.FireAnt.damage
        front = ants.FireAnt()
        side_back = ants.ThrowerAnt()
        side_front = ants.ThrowerAnt()
        armor, side_armor = 20, 10
        bee, side_bee = ants.Bee(armor), ants.Bee(side_armor)

        self.colony.places['tunnel_0_0'].add_insect(back)
        self.colony.places['tunnel_0_2'].add_insect(self.queen)
        self.colony.places['tunnel_0_4'].add_insect(bee)
        self.colony.places['tunnel_1_1'].add_insect(side_back)
        self.colony.places['tunnel_1_3'].add_insect(side_front)
        self.colony.places['tunnel_1_4'].add_insect(side_bee)

        # Simulate a battle in Tunnel 0 (contains Queen)
        back.action(self.colony)
        armor -= thrower_damage  # No doubling until queen's action
        self.assertEqual(armor, bee.armor, "Damage doubled too early")
        self.queen.action(self.colony)
        armor -= thrower_damage  # Queen should always deal normal damage
        self.assertEqual(armor, bee.armor, "Queen damage incorrect")
        bee.action(self.colony)  # Bee moves forward
        self.colony.places['tunnel_0_3'].add_insect(front)  # Fire ant added
        back.action(self.colony)
        armor -= 2 * thrower_damage  # Damage doubled in back
        self.assertEqual(armor, bee.armor, "Back damage incorrect")
        self.queen.action(self.colony)
        armor -= thrower_damage  # Queen should always deal normal damage
        self.assertEqual(armor, bee.armor, "Queen damage incorrect (2)")
        back.action(self.colony)
        armor -= 2 * thrower_damage  # Thrower damage still doubled
        self.assertEqual(armor, bee.armor, "Back damage incorrect (2)")
        bee.action(self.colony)
        armor -= 2 * fire_damage  # Fire damage doubled
        self.assertEqual(armor, bee.armor, "Fire damage incorrect")

        # Simulate a battle in Tunnel 1 (no Queen)
        self.assertEqual(side_armor, side_bee.armor, "Side bee took damage")
        side_back.action(self.colony)
        side_armor -= thrower_damage  # Ant in another tunnel: normal damage
        self.assertEqual(side_armor, side_bee.armor,
                         "Side back damage incorrect")
        side_front.action(self.colony)
        side_armor -= thrower_damage  # Ant in another tunnel: normal damage
        self.assertEqual(side_armor, side_bee.armor,
                         "Side front damage incorrect")
Exemplo n.º 8
0
 def test_double_continuous(self):
     """This test makes the queen buff one ant, then the other, to see
     if the queen will continually buff newly added ants.
     """
     self.colony.places['tunnel_0_0'].add_insect(ants.ThrowerAnt())
     self.colony.places['tunnel_0_2'].add_insect(self.queen)
     self.queen.action(self.colony)
     # Add ant and buff
     ant = ants.ThrowerAnt()
     self.colony.places['tunnel_0_1'].add_insect(ant)
     self.queen.action(self.colony)
     # Attack a bee
     bee = ants.Bee(3)
     self.colony.places['tunnel_0_4'].add_insect(bee)
     ant.action(self.colony)
     self.assertEqual(1, bee.armor, "Queen does not buff new ants")
Exemplo n.º 9
0
 def test_nearest_bee_not_in_hive(self):
     error_msg = 'ThrowerAnt hit a Bee in the Hive'
     ant = ants.ThrowerAnt()
     self.colony.places['tunnel_0_0'].add_insect(ant)
     hive = self.colony.hive
     hive.add_insect(ants.Bee(2))
     self.assertIsNone(ant.nearest_bee(hive), error_msg)
Exemplo n.º 10
0
 def test_thrower(self):
     error_msg = 'ThrowerAnt can\'t throw from inside a bodyguard'
     ant = ants.ThrowerAnt()
     self.colony.places['tunnel_0_0'].add_insect(self.bodyguard)
     self.colony.places['tunnel_0_0'].add_insect(ant)
     bee = ants.Bee(2)
     self.colony.places['tunnel_0_3'].add_insect(bee)
     self.bodyguard.action(self.colony)
     self.assertIs(1, bee.armor, error_msg)
Exemplo n.º 11
0
 def test_thrower(self):
     error_msg = "ThrowerAnt can't throw from inside a bodyguard"
     ant = ants.ThrowerAnt()
     self.colony.places["tunnel_0_0"].add_insect(self.bodyguard)
     self.colony.places["tunnel_0_0"].add_insect(ant)
     bee = ants.Bee(2)
     self.colony.places["tunnel_0_3"].add_insect(bee)
     self.bodyguard.action(self.colony)
     self.assertEqual(1, bee.armor, error_msg)
Exemplo n.º 12
0
 def test_non_ninja_blocks(self):
     error_msg = "Non-NinjaAnt does not block bees"
     p0 = self.colony.places["tunnel_0_0"]
     p1 = self.colony.places["tunnel_0_1"]
     bee = ants.Bee(2)
     p1.add_insect(bee)
     p1.add_insect(ants.ThrowerAnt())
     bee.action(self.colony)
     self.assertIsNot(p0, bee.place, error_msg)
Exemplo n.º 13
0
 def test_water_deadliness_2(self):
     error_msg = 'Water does not kill non-watersafe Insects'
     test_ants = [ants.Bee(1000000), ants.HarvesterAnt(), ants.Ant(), ants.ThrowerAnt()]
     test_ants[0].watersafe = False #Make the bee non-watersafe
     test_water = ants.Water('water_TestProblemA4_0')
     for test_ant in test_ants:
         test_water.add_insect(test_ant)
         self.assertIsNot(test_ant, test_water.ant, msg=error_msg)
         self.assertIs(0, test_ant.armor, msg=error_msg)
Exemplo n.º 14
0
 def test_melee(self):
     error_msg = "ThrowerAnt doesn't attack bees on its own square."
     ant = ants.ThrowerAnt()
     self.colony.places["tunnel_0_0"].add_insect(ant)
     near_bee = ants.Bee(2)
     self.colony.places["tunnel_0_0"].add_insect(near_bee)
     self.assertIs(ant.nearest_bee(self.colony.hive), near_bee, error_msg)
     ant.action(self.colony)
     self.assertIs(1, near_bee.armor, error_msg)
Exemplo n.º 15
0
 def test_nearest_bee(self):
     error_msg = "ThrowerAnt can't find the nearest bee"
     ant = ants.ThrowerAnt()
     self.colony.places["tunnel_0_0"].add_insect(ant)
     near_bee = ants.Bee(2)
     self.colony.places["tunnel_0_3"].add_insect(near_bee)
     self.colony.places["tunnel_0_6"].add_insect(ants.Bee(2))
     hive = self.colony.hive
     self.assertIs(ant.nearest_bee(hive), near_bee, error_msg)
     ant.action(self.colony)
     self.assertEqual(1, near_bee.armor, error_msg)
Exemplo n.º 16
0
 def test_nearest_bee(self):
     error_msg = 'ThrowerAnt can\'t find the nearest bee.'
     ant = ants.ThrowerAnt()
     self.colony.places['tunnel_0_0'].add_insect(ant)
     near_bee = ants.Bee(2)
     self.colony.places['tunnel_0_3'].add_insect(near_bee)
     self.colony.places['tunnel_0_6'].add_insect(ants.Bee(2))
     hive = self.colony.hive
     self.assertIs(ant.nearest_bee(hive), near_bee, error_msg)
     ant.action(self.colony)
     self.assertIs(1, near_bee.armor, error_msg)
Exemplo n.º 17
0
 def test_boost_after_death(self):
     bee = ants.Bee(5)
     thrower = ants.ThrowerAnt()
     thrower_armor = thrower.armor
     self.colony.places['tunnel_0_0'].add_insect(self.princess_daisy)
     self.colony.places['tunnel_0_1'].add_insect(thrower)
     self.princess_daisy.action(self.colony)
     self.colony.places['tunnel_0_0'].add_insect(bee)
     bee.action(self.colony)
     self.assertEqual(
         thrower.armor, thrower_armor + 1,
         "Other ants' armors should remain boosted after princess expires")
Exemplo n.º 18
0
 def test_water_deadliness_with_big_soggy_bee(self):
     error_msg = "Water does not hurt all non-watersafe Insects"
     test_ants = [
         ants.Bee(1000000),
         ants.HarvesterAnt(),
         ants.Ant(),
         ants.ThrowerAnt()
     ]
     test_ants[0].watersafe = False  # Make the Bee non-watersafe
     test_water = ants.Water("water_TestProblemA4_0")
     for test_ant in test_ants:
         test_water.add_insect(test_ant)
         self.assertIsNot(test_ant, test_water.ant, msg=error_msg)
         self.assertIs(0, test_ant.armor, msg=error_msg)
Exemplo n.º 19
0
 def test_double_boost(self):
     thrower = ants.ThrowerAnt()
     thrower_armor = thrower.armor
     princess_armor = self.princess_peach.armor
     self.colony.places['tunnel_0_0'].add_insect(self.princess_peach)
     self.colony.places['tunnel_0_1'].add_insect(thrower)
     self.colony.places['tunnel_0_2'].add_insect(self.princess_daisy)
     self.princess_peach.action(self.colony)
     self.princess_daisy.action(self.colony)
     self.assertEqual(thrower.armor, thrower_armor + 2,
                      "Other ant's armor should have been boosted twice")
     self.assertEqual(self.princess_peach.armor, princess_armor + 1,
                      "Princess armor should have been boosted once")
     self.assertEqual(self.princess_daisy.armor, princess_armor + 1,
                      "Princess armor should have been boosted once")
Exemplo n.º 20
0
    def test_random_shot(self):
        error_msg = "ThrowerAnt does not appear to choose random targets"
        ant = ants.ThrowerAnt()
        self.colony.places["tunnel_0_0"].add_insect(ant)
        # Place two ultra-bees to test randomness.
        bee = ants.Bee(1001)
        self.colony.places["tunnel_0_3"].add_insect(bee)
        self.colony.places["tunnel_0_3"].add_insect(ants.Bee(1001))
        # Throw 1000 times. The first bee should take ~1000*1/2 = ~500 damage,
        # and have ~501 remaining.
        for _ in range(1000):
            ant.action(self.colony)
        # Test if damage to bee 1 is within 6 standard deviations (~95 damage)
        # If bees are chosen uniformly, this is true 99.9999998% of the time.
        def dmg_within_tolerance():
            return abs(bee.armor - 501) < 95

        self.assertIs(True, dmg_within_tolerance(), error_msg)
Exemplo n.º 21
0
 def test_random_shot(self):
     """This test is probabilistic. Even with a correct implementation,
     it will fail about 0.42% of the time.
     """
     error_msg = 'ThrowerAnt does not appear to choose random targets'
     #Place ant
     ant = ants.ThrowerAnt()
     self.colony.places['tunnel_0_0'].add_insect(ant)
     #Place two ultra-bees to test randomness
     bee = ants.Bee(1001)
     self.colony.places['tunnel_0_3'].add_insect(bee)
     self.colony.places['tunnel_0_3'].add_insect(ants.Bee(1001))
     
     #Throw 1000 times. bee should take ~1000*1/2 = ~500 damage,
     #and have ~501 remaining.
     for _ in range(1000):
         ant.action(self.colony)
     #Test if damage to bee 1 is within 3 SD (~46 damage)
     def dmg_within_tolerance():
         return abs(bee.armor-501) < 46
     self.assertIs(True, dmg_within_tolerance(), error_msg)
Exemplo n.º 22
0
colony = AntColony(None, hive, ant_types(), layout, (1, 9))
#
# Testing bodyguard performs thrower's action
bodyguard = BodyguardAnt()
thrower = ThrowerAnt()
bee = Bee(2)
# Place thrower before bodyguard
colony.places["tunnel_0_0"].add_insect(thrower)
colony.places["tunnel_0_0"].add_insect(bodyguard)
colony.places["tunnel_0_3"].add_insect(bee)
bodyguard.action(colony)
'''
import ants, importlib
importlib.reload(ants)
hive = ants.Hive(ants.AssaultPlan())
dimensions = (2, 9)
colony = ants.AntColony(None, hive, ants.ant_types(), ants.dry_layout,
                        dimensions)
ants.bees_win = lambda: None
# QueenAnt Placement
queen = ants.QueenAnt()
impostor = ants.QueenAnt()
front_ant, back_ant = ants.ThrowerAnt(), ants.ThrowerAnt()
tunnel = [colony.places['tunnel_0_{0}'.format(i)] for i in range(9)]
tunnel[1].add_insect(back_ant)
tunnel[7].add_insect(front_ant)
tunnel[4].add_insect(impostor)
impostor.action(colony)
tunnel[4].add_insect(queen)
queen.action(colony)
Exemplo n.º 23
0
import ants, importlib
importlib.reload(ants)
hive = ants.Hive(ants.AssaultPlan())
dimensions = (2, 9)
colony = ants.AntColony(None, hive, ants.ant_types(),
        ants.dry_layout, dimensions)
ants.bees_win = lambda: None
# Testing damage multiplier
queen_tunnel, side_tunnel = [[colony.places['tunnel_{0}_{1}'.format(i, j)]
        for j in range(9)] for i in range(2)]
queen = ants.QueenAnt()
back = ants.ThrowerAnt()
front = ants.ThrowerAnt()
guard = ants.BodyguardAnt()
guarded = ants.ThrowerAnt()
side = ants.ThrowerAnt()
bee = ants.Bee(10)
side_bee = ants.Bee(10)
queen_tunnel[0].add_insect(back)
queen_tunnel[1].add_insect(guard)
queen_tunnel[1].add_insect(guarded)
queen_tunnel[2].add_insect(queen)
queen_tunnel[3].add_insect(front)
side_tunnel[0].add_insect(side)
queen_tunnel[4].add_insect(bee)
side_tunnel[4].add_insect(side_bee)
queen.action(colony)
guard.action(colony)
Exemplo n.º 24
0
import ants, importlib
importlib.reload(ants)
hive = ants.Hive(ants.AssaultPlan())
dimensions = (2, 9)
colony = ants.AntColony(None, hive, ants.ant_types(), ants.dry_layout,
                        dimensions)

queen_tunnel, side_tunnel = [[
    colony.places['tunnel_{0}_{1}'.format(i, j)] for j in range(9)
] for i in range(2)]
queen = ants.QueenAnt()
queen_tunnel[7].add_insect(queen)
print('Turn1----------------------------')
thrower = ants.ThrowerAnt()
fire = ants.FireAnt()
ninja = ants.NinjaAnt()
side = ants.ThrowerAnt()
front = ants.NinjaAnt()
queen_tunnel[0].add_insect(thrower)
queen_tunnel[1].add_insect(fire)
queen_tunnel[2].add_insect(ninja)
queen_tunnel[8].add_insect(front)
side_tunnel[0].add_insect(side)
queen.action(colony)
print('Turn2--------------------------------')
tank = ants.TankAnt()
guard = ants.BodyguardAnt()
queen_tank = ants.TankAnt()
queen_tunnel[6].add_insect(tank)
print("insert tank")
queen_tunnel[1].add_insect(guard)