예제 #1
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)]
예제 #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]

        if self.location == self.target:
            return ['guard']
        return ['move', rg.toward(self.location, self.target)]
예제 #3
0
파일: team_2.py 프로젝트: takluyver/rgkit
    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):
        enemies = self.enemies(game)
        global_weakest = self.weakest(enemies)

        local_weakest = self.weakest(
            self.adjacent_enemies(enemies))

        if local_weakest:
            return ['attack', local_weakest.location]
        return ['move', rg.toward(self.location, global_weakest.location)]
예제 #5
0
 def _spawn_action(self):
     if Robot._spawn_test(self.location):
         normal, spawn = Robot._surrounding(self.location)
         if normal:
             n_occu, n_unoccu = Robot._occupied_find(normal, self.game)
             if n_unoccu:
                 return ["move", rg.toward(self.location, n_unoccu[0])]
             else:
                 for i in n_occu:
                     friend_test = Robot._test_friend_bot(self.player_id, i, self.game)
                     if friend_test == "friend":
                         pass
                     else:
                         return ["attack", i]
         if spawn:
             s_occu, s_unoccu = Robot._occupied_find(spawn, self.game)
             if s_unoccu:
                 return ["move", rg.toward(self.location, s_unoccu[0])]
     else:
         return None
예제 #6
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)]
    def act(self, game):
        if self.location == rg.CENTER_POINT:
            return ['guard']

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

        # move toward the center
        return ['move', rg.toward(self.location, rg.CENTER_POINT)]
    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)]
예제 #9
0
    def act(self, game):
        move = self.choose_move()

        def add(xy, dxdy):
            dx, dy = dxdy
            x, y = xy
            return (x + dx, y + dy)

        if move[0] == "move":
            direction = rg.toward(self.location, self.RALLY_POINT)
            return ["move", direction]
        if move[0] == "attack":
            # import pdb; pdb.set_trace()
            pos = add(self.location, move[1])
            return ["attack", pos]
        return move
예제 #10
0
    def commandMove(self, game):
        #########################################################################
        #Jeżeli kilka z sojuszniczych robotów chce wejść na to samo pole,
        #wszystkie opróch jednego mają ustawiony status 'guard'
        #########################################################################
        values.commands[self.robot_id]['toward'] = rg.toward(
            self.location, values.commands[self.robot_id]['destination'])

        for _, bots in game.robots.iteritems():
            if self.player_id == bots.player_id:
                if bots.robot_id == self.robot_id:
                    continue

                if len(values.commands[bots.robot_id]['toward']) != 0:
                    if values.commands[bots.robot_id]['toward'] == \
                            values.commands[self.robot_id]['toward']:
                        values.commands[self.robot_id]['action'] = 'guard'
예제 #11
0
 def _near_spawn_action(self):
     normal, spawn = Robot._surrounding(self.location)
     if spawn:
         s_occu, s_unoccu = Robot._occupied_find(spawn, self.game)
         if s_occu:
             for i in s_occu:
                 friend_test = Robot._test_friend_bot(self.player_id, i, self.game)
                 if friend_test == "friend":
                     return ["move", rg.toward(self.location, rg.CENTER_POINT)]
                 else:
                     return ["attack", i]
     if normal:
         o_occu, o_unoccu = Robot._occupied_find(normal, self.game)
         if o_occu:
             for i in o_occu:
                 friend_test = Robot._test_friend_bot(self.player_id, i, self.game)
                 if friend_test == "friend":
                     continue
                 return ["attack", i]
     return ['guard']
예제 #12
0
파일: rg_test.py 프로젝트: mic159/rgkit
 def test_toward_obstacle(self):
     self.assertEqual(rg.toward((5, 2), (4, 3)), (5, 3))
예제 #13
0
파일: rg_test.py 프로젝트: mic159/rgkit
 def test_toward(self):
     self.assertTrue(rg.toward((5, 13), (8, 3)) in [(5, 12), (6, 13)])
 def act(self, game):
     if self.location == rg.CENTER_POINT:
         return ['suicide']
     return ['move', rg.toward(self.location, rg.CENTER_POINT)]
예제 #15
0
 def test_toward_obstacle(self):
     self.assertEqual(rg.toward((5, 2), (4, 3)), (5, 3))
예제 #16
0
 def test_toward(self):
     self.assertTrue(rg.toward((5, 13), (8, 3)) in [(5, 12), (6, 13)])