Example #1
0
    def setUp(self):
        self.w = SecurityWorld()
        self.wt = worldtalker.WorldTalker(self.w)
        self.own_ai = SecurityAI(self.wt)
        self.other_ai = SecurityAI(self.wt)

        top_left = (0, 0)
        bottom_right = (self.w.mapSize - 1, self.w.mapSize - 1)

        self.top_left = top_left
        self.bottom_right = bottom_right

        s = world.Stats(ai_id=self.own_ai.ai_id, team=self.own_ai.team)
        s.ai = self.own_ai
        self.own_unit = self.w.createUnit(s, top_left)

        s = world.Stats(ai_id=self.other_ai.ai_id, team=self.other_ai.team)
        s.ai = self.other_ai
        self.other_unit = self.w.createUnit(s, bottom_right)

        b = mapobject.Building(self.wt)
        self.w.buildings[b] = self.own_ai
        self.w.map.placeObject(b, top_left)
        self.own_b = b

        b = mapobject.Building(self.wt)
        self.w.buildings[b] = self.other_ai
        self.w.map.placeObject(b, bottom_right)

        self.other_b = b
Example #2
0
 def test_melee_no_friendly_fire(self):
     s = world.Stats(ai_id=self.ai.ai_id, team=self.ai.team)
     friendly_unit = self.w.createUnit(s, self.top_left)
     self.assertEqual(friendly_unit in self.w.units, True)
     self.w.map.placeObject(self.unit, self.top_left)
     self.w.currentTurn = settings.UNIT_SPAWN_MOD + 1
     self.w.createShootEvent(self.unit, self.top_left, 1)
     self.w.Turn()
     self.assertEqual(friendly_unit in self.w.units, True)
Example #3
0
 def test_melee(self):
     other_ai = SecurityAI(self.wt)
     s = world.Stats(ai_id=other_ai.ai_id, team=other_ai.team)
     s.ai = other_ai
     other_unit = self.w.createUnit(s, self.top_left)
     self.assertEqual(other_unit in self.w.units, True)
     self.w.map.placeObject(self.unit, self.top_left)
     self.w.currentTurn = settings.UNIT_SPAWN_MOD + 1
     self.w.createShootEvent(self.unit, self.top_left, 1)
     self.w.Turn()
     self.assertEqual(other_unit in self.w.units, False)
Example #4
0
    def test_shoot_does_not_hit_distant_enemy(self):
        self.w.map.placeObject(self.unit, self.top_left)
        other_ai = SecurityAI(self.wt)
        s = world.Stats(ai_id=other_ai.ai_id, team=other_ai.team)
        s.ai = other_ai
        other_unit = self.w.createUnit(s, self.bottom_right)
        self.ai.do_unit_action(self.unit, "shoot", self.bottom_right)
        energy = self.w.units[other_unit].energy

        self.w.Turn()
        self.assertEqual(energy, self.w.units[other_unit].energy)
Example #5
0
    def test_shoot_deals_damage(self):
        self.w.map.placeObject(self.unit, self.top_left)
        other_ai = SecurityAI(self.wt)
        s = world.Stats(ai_id=other_ai.ai_id, team=other_ai.team)
        s.ai = other_ai
        other_unit = self.w.createUnit(s, (5, 5))
        self.ai.do_unit_action(self.unit, "shoot", (5, 5))
        energy = self.w.units[other_unit].energy

        self.w.Turn()
        self.assertNotEqual(energy, self.w.units[other_unit].energy)
Example #6
0
    def test_shoot_can_kill_enemy(self):
        self.w.map.placeObject(self.unit, self.top_left)
        other_ai = SecurityAI(self.wt)
        s = world.Stats(ai_id=other_ai.ai_id, team=other_ai.team)
        s.ai = other_ai
        other_unit = self.w.createUnit(s, (5, 5))

        while other_unit in self.w.units:
            energy = self.w.units[other_unit].energy
            self.ai.do_unit_action(self.unit, "shoot", (5, 5))
            self.w.Turn()
            if not other_unit in self.w.units:
                break

            self.assertNotEqual(energy, self.w.units[other_unit].energy)
Example #7
0
    def test_melee_kill_all_enemies(self):
        enemies = []
        self.w.map.placeObject(self.unit, self.top_left)

        for x in xrange(5):
            other_ai = SecurityAI(self.wt)
            s = world.Stats(ai_id=other_ai.ai_id, team=other_ai.team)
            s.ai = other_ai
            other_unit = self.w.createUnit(s, self.top_left)
            enemies.append(other_unit)

        for other_unit in enemies:
            self.assertEqual(other_unit in self.w.units, True)

        self.w.currentTurn = settings.UNIT_SPAWN_MOD + 1
        self.w.createShootEvent(self.unit, self.top_left, 1)
        self.w.Turn()
        for other_unit in enemies:
            self.assertEqual(other_unit in self.w.units, False)