def act(self, game):
        allies = self.allies(game)
        enemies = self.enemies(game)
        strongest = self.strongest(allies)

        # Attack any adjacent enemies
        for loc, enemy in enemies.iteritems():
            if rg.dist(loc, self.location) <= 1:
                return ['attack', loc]

        # Guard when nearby allies
        if rg.dist(self.location, strongest.location) <= 3:
            return ['guard']

        return ['move', rg.toward(self.location, strongest.location)]
Beispiel #2
0
    def act(self, game):
        enemies = []
        myx, myy = self.location
        for dx in (-1, 0, 1):
            for dy in (-1, 0, 1):
                x = myx + dx
                y = myy + dy
                target = game.robots.get((x, y), None)
                if (target and target.player_id != self.player_id
                        and (dx == 0 or dy == 0)):
                    enemies.append(target)

        weak_count = 0
        for enemy in enemies:
            if enemy.hp <= 15:
                weak_count = weak_count + 1
        if weak_count >= 2:
            return ['suicide']

        if enemies:
            return ['attack', enemies[0].location]

        closest_target = None
        closest_distance = 1000000
        for target in game.robots.values():
            if target.player_id != self.player_id:
                distance = rg.dist(self.location, target.location)
                if distance < closest_distance:
                    closest_target = target
                    closest_distance = distance

        return ['move', rg.toward(self.location, closest_target.location)]
Beispiel #3
0
    def act(self, game):
        # if we're in the center, stay put
        if self.location == rg.CENTER_POINT:
            return ['guard']

        # if there are enemies around, attack them
        for loc, bot in game.robots.items():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]

                anticipated_loc = rg.toward(loc, rg.CENTER_POINT)
                if rg.dist(anticipated_loc, self.location) <= 1:
                    return ['attack', anticipated_loc]

        # move toward the center
        return ['move', rg.toward(self.location, rg.CENTER_POINT)]
    def act(self, game):
        if self.location == rg.CENTER_POINT:
            return super(Robot, self).guard()

        for bot in game.robots:
            if bot.player_id != self.player_id:
                if rg.dist(bot.location, self.location) <= 1:
                    return super(Robot, self).attack_location(bot.location)

        return super(Robot, self).move_towards(rg, rg.CENTER_POINT)
Beispiel #5
0
    def act(self, game):
        p = INVINCICIDE()

        # stock code stolen from the RGKit default robot, but with 'guard' and
        # 'attack' replaced with INVINCICIDE
        if self.location == rg.CENTER_POINT:
            return INVINCICIDE()
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return INVINCICIDE()
        return ['move', rg.toward(self.location, rg.CENTER_POINT)]
Beispiel #6
0
        def mindist(bots, loc):
            return min(bots, key=lambda x: rg.dist(x, loc))

            if enemy:
                closest_enemy = mindist(enemy, self.location)
            else
            closest_enemy = rg.CENTER_POINT

            move = ['guard']

            if self.location in spawn:
                if safe:
                    move = ['move', mindist(safe, rg.CENTER_POINT)]
            elif adjacent_enemy:
                if 9 * len(adjacent_enemy) >= self.hp:
                    if safe:
                        move = ['move', mindist(safe, rg.CENTER_POINT)]
                else:
                    move = ['attack', adjacent_enemy.pop()]
            elif adjacent_enemy2:
                move = ['attack', adjacent_enemy2.pop()]
            elif safe:
                move = ['move', mindist(safe, closest_enemy)]
 def adjacent_enemies(self, enemies):
     return {loc: enemy
             for loc, enemy
             in enemies.iteritems()
             if rg.dist(loc, self.location) <= 1}