Esempio n. 1
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")
Esempio n. 2
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")
Esempio n. 3
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)
Esempio n. 4
0
 def test_fire_damage(self):
     error_msg = 'FireAnt does the wrong amount of damage'
     place = self.colony.places['tunnel_0_0']
     bee = ants.Bee(5)
     place.add_insect(bee)
     place.add_insect(ants.FireAnt())
     bee.action(self.colony)
     self.assertIs(2, bee.armor, error_msg)
Esempio n. 5
0
 def test_fire_deadliness(self):
     error_msg = 'FireAnt does not damage all Bees in its Place'
     test_place = self.colony.places['tunnel_0_0']
     bee = ants.Bee(3)
     test_place.add_insect(bee)
     test_place.add_insect(ants.Bee(3))
     test_place.add_insect(ants.FireAnt())
     bee.action(self.colony)
     self.assertIs(0, len(test_place.bees), error_msg)
Esempio n. 6
0
 def test_fireant_expiration(self):
     error_msg = "FireAnt should have, but did not expire"
     place = self.colony.places["tunnel_0_0"]
     bee = ants.Bee(1)
     place.add_insect(bee)
     ant = ants.FireAnt()
     place.add_insect(ant)
     bee.action(self.colony)
     self.assertEqual(ant.armor, 0, error_msg)
Esempio n. 7
0
 def test_fire_damage_is_instance_attribute(self):
     error_msg = "FireAnt damage is not looked up on the instance"
     place = self.colony.places["tunnel_0_0"]
     bee = ants.Bee(900)
     place.add_insect(bee)
     buffAnt = ants.FireAnt()
     buffAnt.damage = 500  # Feel the burn!
     place.add_insect(buffAnt)
     bee.action(self.colony)
     self.assertEqual(400, bee.armor, error_msg)
Esempio n. 8
0
 def test_fire_mod_damage(self):
     error_msg = 'FireAnt damage should not be static'
     place = self.colony.places['tunnel_0_0']
     bee = ants.Bee(900)
     place.add_insect(bee)
     #Amp up damage
     buffAnt = ants.FireAnt()
     buffAnt.damage = 500
     place.add_insect(buffAnt)        
     bee.action(self.colony)
     self.assertEqual(400, bee.armor, error_msg)
Esempio n. 9
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")
Esempio n. 10
0
 def test_fire_parameters(self):
     fire = ants.FireAnt()
     self.assertIs(4, ants.FireAnt.food_cost, 'FireAnt has wrong food cost')
     self.assertIs(1, fire.armor, 'FireAnt has wrong armor value')
Esempio n. 11
0
 def test_fire_parameters(self):
     fire = ants.FireAnt()
     self.assertEqual(4, ants.FireAnt.food_cost, "FireAnt has wrong cost")
     self.assertEqual(1, fire.armor, "FireAnt has wrong armor value")
Esempio n. 12
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)