コード例 #1
0
ファイル: robot1.py プロジェクト: TCheetham94/team_bots
    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
ファイル: robot1.py プロジェクト: nathanielknight/team_bots
    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)]
コード例 #4
0
    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
ファイル: algorithm_bot.py プロジェクト: tczorro/robot
 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
ファイル: draxx.py プロジェクト: wgreenberg/robotgame
    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)]
コード例 #8
0
    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
ファイル: robot2.py プロジェクト: nathanielknight/team_bots
    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
ファイル: algorithm_bot.py プロジェクト: tczorro/robot
 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
ファイル: rg_test.py プロジェクト: saavedra29/rgkit_py3
 def test_toward_obstacle(self):
     self.assertEqual(rg.toward((5, 2), (4, 3)), (5, 3))
コード例 #16
0
ファイル: rg_test.py プロジェクト: saavedra29/rgkit_py3
 def test_toward(self):
     self.assertTrue(rg.toward((5, 13), (8, 3)) in [(5, 12), (6, 13)])