def setUp(self): imp.reload(ants) hive = ants.Hive(ants.make_test_assault_plan()) layout = TestProblem9.queen_layout self.colony = ants.AntColony(None, hive, ants.ant_types(), layout) self.queen = ants.QueenAnt() self.imposter = ants.QueenAnt()
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)
class TestProblem9(AntTest): queen = ants.QueenAnt() imposter = ants.QueenAnt() 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") def test_die(self): bee = ants.Bee(3) self.colony.places['tunnel_0_1'].add_insect(TestProblem9.queen) 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') def test_imposter(self): queen = TestProblem9.queen imposter = TestProblem9.imposter self.colony.places['tunnel_0_0'].add_insect(queen) self.colony.places['tunnel_0_1'].add_insect(imposter) queen.action(self.colony) imposter.action(self.colony) self.assertEqual(1, queen.armor, 'Long live the queen') self.assertEqual(0, imposter.armor, 'Imposters must die') 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') def test_remove(self): queen = TestProblem9.queen imposter = TestProblem9.imposter p0 = self.colony.places['tunnel_0_0'] p1 = self.colony.places['tunnel_0_1'] p0.add_insect(queen) p1.add_insect(imposter) p0.remove_insect(queen) p1.remove_insect(imposter) self.assertIs(queen, p0.ant, 'Queen removed') self.assertIs(None, p1.ant, 'Imposter not removed') def test_die_the_old_fashioned_way(self): bee = ants.Bee(3) queen = TestProblem9.queen # The bee has an uninterrupted path to the heart of the colony self.colony.places['tunnel_0_1'].add_insect(bee) self.colony.places['tunnel_0_2'].add_insect(queen) queen.action(self.colony) bee.action(self.colony) self.assertIs(False, len(self.colony.queen.bees) > 0, 'Game ended') queen.action(self.colony) bee.action(self.colony) self.assertIs(True, len(self.colony.queen.bees) > 0, 'Game not ended') 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') if not place.ant.container: # If bodyguard is removed, the queen should still remain self.assertIs(place.ant, queen, error_msg) if place.ant.container: # Bodyguard ant should still contain queen, if it isn't removed self.assertIs(place.ant.ant, queen, error_msg) 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(TestProblem9.queen) TestProblem9.queen.action(self.colony) #Add ant and buff ant = ants.ThrowerAnt() self.colony.places['tunnel_0_1'].add_insect(ant) TestProblem9.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")
class TestProblem9(AntTest): queen = ants.QueenAnt() imposter = ants.QueenAnt() 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 damage incorrect") front.action(self.colony) armor -= thrower_damage # Front is in front, not behind self.assertEqual(armor, bee.armor, "Front damage 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 damage incorrect") TestProblem9.queen.action(self.colony) armor -= thrower_damage self.assertEqual(armor, bee.armor, "Queen damage incorrect (2)") thrower.action(self.colony) armor -= 2 * thrower_damage # Thrower damage doubled self.assertEqual(armor, bee.armor, "Thrower damage 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 damage incorrect") def test_die(self): bee = ants.Bee(3) self.colony.places['tunnel_0_1'].add_insect(TestProblem9.queen) self.colony.places['tunnel_0_2'].add_insect(bee) TestProblem9.queen.action(self.colony) 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') def test_imposter(self): queen = TestProblem9.queen imposter = TestProblem9.imposter self.colony.places['tunnel_0_0'].add_insect(queen) self.colony.places['tunnel_0_1'].add_insect(imposter) queen.action(self.colony) imposter.action(self.colony) self.assertEqual(1, queen.armor, 'Long live the queen') self.assertEqual(0, imposter.armor, 'Imposters must die') 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.assertFalse(len(self.colony.queen.bees) > 0, 'Game ended') bee.action(self.colony) self.assertTrue(len(self.colony.queen.bees) > 0, 'Game not ended') def test_remove(self): queen = TestProblem9.queen imposter = TestProblem9.imposter p0 = self.colony.places['tunnel_0_0'] p1 = self.colony.places['tunnel_0_1'] p0.add_insect(queen) p1.add_insect(imposter) p0.remove_insect(queen) p1.remove_insect(imposter) self.assertIs(queen, p0.ant, 'Queen removed') self.assertIsNone(p1.ant, 'Imposter not removed') def test_die_the_old_fashioned_way(self): bee = ants.Bee(3) queen = TestProblem9.queen # The bee has an uninterrupted path to the heart of the colony self.colony.places['tunnel_0_1'].add_insect(bee) self.colony.places['tunnel_0_2'].add_insect(queen) queen.action(self.colony) bee.action(self.colony) self.assertFalse(len(self.colony.queen.bees) > 0, 'Game ended') queen.action(self.colony) bee.action(self.colony) self.assertTrue(len(self.colony.queen.bees) > 0, 'Game not ended')
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)
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)
def setUp(self): imp.reload(ants) AntTest.setUp(self) self.queen = ants.QueenAnt() self.imposter = ants.QueenAnt()