Ejemplo n.º 1
0
 def test_modified_guard(self):
     #Test to see if we can contain a non-container bodyguard
     error_msg = 'Containable status should not be hard-coded'
     bodyguard = ants.BodyguardAnt()
     mod_guard = ants.BodyguardAnt()
     mod_guard.container = False
     self.assertTrue(bodyguard.can_contain(mod_guard), error_msg)
Ejemplo n.º 2
0
 def setUp(self):
     AntTest.setUp(self)
     self.place = ants.Place('TestProblem8')
     self.bodyguard = ants.BodyguardAnt()
     self.bodyguard2 = ants.BodyguardAnt()
     self.test_ant = ants.Ant()
     self.test_ant2 = ants.Ant()
     self.harvester = ants.HarvesterAnt()
Ejemplo 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)
Ejemplo n.º 4
0
 def test_remove_bodyguard(self):
     error_msg = 'Removing BodyguardAnt also removes containing ant'
     place = self.colony.places['tunnel_0_0']
     bodyguard = ants.BodyguardAnt()
     test_ant = ants.Ant(1)
     place.add_insect(bodyguard)
     place.add_insect(test_ant)
     self.colony.remove_ant('tunnel_0_0')
     self.assertIs(place.ant, test_ant, error_msg)
Ejemplo n.º 5
0
 def test_bodyguard(self):
     bee = ants.Bee(3)
     guard = ants.BodyguardAnt()
     self.colony.places['tunnel_0_1'].add_insect(TestProblem9.queen)
     self.colony.places['tunnel_0_1'].add_insect(guard)
     self.colony.places['tunnel_0_2'].add_insect(bee)
     TestProblem9.queen.action(self.colony)
     self.assertIs(False, len(self.colony.queen.bees) > 0, 'Game ended')
     bee.action(self.colony)
     self.assertIs(True, len(self.colony.queen.bees) > 0, 'Game not ended')
Ejemplo n.º 6
0
 def test_double_bodyguarded_princesses(self):
     peach_bodyguard = ants.BodyguardAnt()
     daisy_bodyguard = ants.BodyguardAnt()
     princess_armor = self.princess_peach.armor
     bodyguard_armor = peach_bodyguard.armor
     self.colony.places['tunnel_0_0'].add_insect(self.princess_peach)
     self.colony.places['tunnel_0_0'].add_insect(peach_bodyguard)
     self.colony.places['tunnel_0_1'].add_insect(self.princess_daisy)
     self.colony.places['tunnel_0_1'].add_insect(daisy_bodyguard)
     self.princess_peach.action(self.colony)
     self.princess_daisy.action(self.colony)
     self.assertEqual(peach_bodyguard.armor, bodyguard_armor + 2,
                      "Armor for BodyguardAnt incorrectly boosted")
     self.assertEqual(daisy_bodyguard.armor, bodyguard_armor + 2,
                      "Armor for BodyguardAnt incorrectly boosted")
     self.assertEqual(self.princess_peach.armor, princess_armor,
                      "Armor for protected princess should not be boosted")
     self.assertEqual(self.princess_daisy.armor, princess_armor,
                      "Armor for protected princess should not be boosted")
Ejemplo n.º 7
0
 def test_bodyguard(self):
     bee = ants.Bee(3)
     guard = ants.BodyguardAnt()
     guard.damage, doubled = 5, 10
     self.colony.places['tunnel_0_1'].add_insect(self.queen)
     self.colony.places['tunnel_0_1'].add_insect(guard)
     self.colony.places['tunnel_0_2'].add_insect(bee)
     self.queen.action(self.colony)
     self.assertEqual(guard.damage, doubled, 'Bodyguard damage incorrect')
     self.assertFalse(len(self.colony.queen.bees) > 0, 'Game ended')
     bee.action(self.colony)
     self.assertTrue(len(self.colony.queen.bees) > 0, 'Game not ended')
Ejemplo n.º 8
0
 def test_removing_bodyguarded_queen(self):
     error_msg = 'Bodyguarded queen can be removed!'
     queen = TestProblem9.queen
     guard = ants.BodyguardAnt()
     place = self.colony.places['tunnel_0_0']
     place.add_insect(queen)
     place.add_insect(guard)
     self.colony.remove_ant('tunnel_0_0')
     self.assertIs(place.ant, queen, error_msg)
     if place.ant.container:
         # Bodyguard ant should still contain queen, if it isn't removed
         self.assertFalse(place.ant.ant, queen, error_msg)
Ejemplo n.º 9
0
 def test_bodyguarded_princess(self):
     bodyguard = ants.BodyguardAnt()
     bodyguard_armor = bodyguard.armor
     princess_armor = self.princess_peach.armor
     self.colony.places['tunnel_0_0'].add_insect(self.princess_peach)
     self.colony.places['tunnel_0_0'].add_insect(bodyguard)
     self.princess_peach.action(self.colony)
     bodyguard.action(self.colony)
     self.assertEqual(bodyguard.armor, bodyguard_armor + 1,
                      "Armor for BodyguardAnt incorrectly boosted")
     self.assertEqual(self.princess_peach.armor, princess_armor,
                      "Armor for protected princess should not be boosted")
Ejemplo n.º 10
0
    def test_bodyguarded_ant_do_action(self):
        error_msg = "Bodyguarded ant does not perform its action"

        class TestAnt(ants.Ant):
            def action(self, colony):
                self.armor += 9000

        test_ant = TestAnt(1)
        place = self.colony.places['tunnel_0_0']
        bodyguard = ants.BodyguardAnt()
        place.add_insect(test_ant)
        place.add_insect(bodyguard)
        place.ant.action(self.colony)
        self.assertEqual(place.ant.ant.armor, 9001, error_msg)
Ejemplo n.º 11
0
 def test_remove_bodyguard(self):
     """This tests the following statement:
     "If a BodyguardAnt containing another ant is removed, then the
     ant it is containing should be placed where the BodyguardAnt
     used to be."
     Since this is optional, you can get a full score even if your
     program fails this doctest."""
     error_msg = 'Removing BodyguardAnt also removes containing ant'
     place = self.colony.places['tunnel_0_0']
     bodyguard = ants.BodyguardAnt()
     test_ant = ants.Ant(1)
     place.add_insect(bodyguard)
     place.add_insect(test_ant)
     self.colony.remove_ant('tunnel_0_0')
     self.assertIs(place.ant, test_ant, error_msg)
Ejemplo n.º 12
0
 def test_bodyguard_parameters(self):
     bodyguard = ants.BodyguardAnt()
     self.assertIs(4, ants.BodyguardAnt.food_cost,
                   'BodyguardAnt has wrong cost')
     self.assertIs(2, bodyguard.armor, 'BodyguardAnt has wrong armor')
Ejemplo n.º 13
0
 def test_modified_guard(self):
     error_msg = "A container should not contain another container."
     bodyguard = ants.BodyguardAnt()
     mod_guard = ants.BodyguardAnt()
     mod_guard.container = False
     self.assertTrue(bodyguard.can_contain(mod_guard), error_msg)
Ejemplo n.º 14
0
 def test_bodyguard_parameters(self):
     bodyguard = ants.BodyguardAnt()
     self.assertEqual(4, ants.BodyguardAnt.food_cost,
                      "BodyguardAnt has wrong cost")
     self.assertEqual(2, bodyguard.armor, "BodyguardAnt has wrong armor")
Ejemplo n.º 15
0
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)
queen_tunnel[7].add_insect(queen_tank)
queen.action(colony)
print('Turn3--------------------------')
thrower1 = ants.ThrowerAnt()
thrower2 = ants.ThrowerAnt()
queen_tunnel[6].add_insect(thrower1)

queen_tunnel[5].add_insect(thrower2)
queen.action(colony)