Example #1
0
def empty_score(this_robot, loc, game):
    score = 0
    if (verbose > 1): print "here"
    if (this_robot.hp > 25):
        score -= abs(
            rg.dist(loc, rg.CENTER_POINT) -
            best_center_distance_param) * best_center_distance_weight
    else:
        score -= rg.dist(loc, rg.CENTER_POINT) * best_center_distance_weight
    if (verbose > 1): print "here2"
    for loc2 in rg.locs_around(loc, filter_out=('obstacle', 'invalid')):
        if (loc2 in game.robots):
            if (game.robots[loc2].player_id != this_robot.player_id):
                score -= adjacent_robot_penalty
            else:
                score -= adjacent_friendly_penalty
    #if we are trying to run away from spawn, non-spawn adjacent squares with no enemies by them are good, because we need to move
    if (spawn(loc) & game.turn < 91):
        for loc2 in rg.locs_around(loc, filter_out=('obstacle', 'invalid')):
            clear_square = 1
            for loc3 in rg.locs_around(loc2,
                                       filter_out=('obstacle', 'invalid',
                                                   'spawn')):
                if (loc3 in game.robots and
                        game.robots[loc3].player_id != this_robot.player_id):
                    clear_square = 0
            score += ((game.turn + 1) % 10) * spawn_weight * clear_square / 2
    if (spawn(loc) & game.turn < 91):
        score -= ((game.turn + 1) % 10) * spawn_weight
    if (surrounded_spawn(loc) & game.turn < 91):
        score -= (game.turn % 10) * spawn_weight
    return score
Example #2
0
def attack_moving_enemy(this_robot, game, illegals):
    if (this_robot.location in illegals): return 'no_action'
    square_dictionary = {}
    for square in rg.locs_around(this_robot.location):
        square_dictionary[square] = 0
        if square in game.robots:
            square_dictionary[
                square] -= 40  #don't fire if our robot is there, they probably won't move there
    for bot in two_robots:
        if bot.player_id != this_robot.player_id:
            loc = bot.location
            targetx = towardx(this_robot.location, loc)
            targety = towardy(this_robot.location, loc)
            if targetx != 'no_move':
                square_dictionary[targetx] += 70 - bot.hp - rg.dist(
                    rg.CENTER_POINT, targetx)
            if targety != 'no_move':
                square_dictionary[targety] += 70 - bot.hp - rg.dist(
                    rg.CENTER_POINT, targety)
    best_score = 0
    best_move = 'no_action'
    for square in rg.locs_around(this_robot.location):
        if square_dictionary[square] > best_score:
            best_score = square_dictionary[square]
            best_move = ['attack', square]
    return best_move
Example #3
0
 def act(self, game):
   # We don't want to die during spawn turns so we move to an empty
   # non-spawn position
   if game.turn % rg.settings.spawn_every == 0 and "spawn" in rg.loc_types(self.location):
     empty_pos = rg.locs_around(self.location, filter_out=("invalid", "obstacle", "spawn"))
     if empty_pos:
       return ["move", empty_pos[0]]
     else:
       return ["suicide"]
   # Move to one of the "quarters"
   around = rg.locs_around(self.location, filter_out=("obstacle", "invalid"))
   position = rg.toward(self.location, random.choice(self.DIRECTION))
   position = self.closest(around, position)
   action = "move"
   if self.is_surrounded(game):
     return ["suicide"]
   # By the end we guard if we have low hp
   if 0 < self.hp < 15 and (rg.settings.max_turns - game.turn) < 5:
     return ["guard"]
   # Attack the weakest opponent around if any
   weakest = self.weakest_opponent(game)
   if weakest:
     # We go KABOOOOOM if we're low on hp!!
     if self.hp < 10:
       return ["suicide"]
     return ["attack", weakest.location]
   return [action, position]
Example #4
0
    def act(self, game):

        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        wejscia = {poz for poz in wszystkie if 'spawn' in rg.loc_types(poz)}
        zablokowane = {poz for poz in wszystkie if 'obstacle' in rg.loc_types(poz)}
        druzyna = {poz for poz in game.robots if game.robots[poz].player_id == self.player_id}
        wrogowie = set(game.robots) - druzyna
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {poz for poz in sasiednie if (set(rg.locs_around(poz)) & wrogowie)} - druzyna

        # działanie domyślne:
        ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]

        if self.location in wejscia:
            ruch = ['move',  rg.toward(self.location, rg.CENTER_POINT)]

        if self.location == rg.CENTER_POINT:
            ruch = ['guard']

        if sasiednie_wrogowie:
            if 9*len(sasiednie_wrogowie) >= self.hp:
                pass
            else:
                ruch = ['attack', sasiednie_wrogowie.pop()]

        if sasiednie_wrogowie2:
            ruch = ['attack', sasiednie_wrogowie2.pop()]

        return ruch
Example #5
0
    def act(self, game):

        # zbiory pól na planszy

        # wszystkie pola
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}

        # punkty wejścia (spawn)
        wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}

        # pola zablokowane (obstacle)
        zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}

        # pola zajęte przez nasze roboty
        druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}

        # pola zajęte przez wrogów
        wrogowie = set(game.robots) - druzyna

        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna

        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna

        print wejscia
        # domyślne działanie robota: ruch do środka
        ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]

        return ruch
Example #6
0
    def _analyze_explosions(self):
        turn = self.current_turn
        old_enemiesl = {x.location: x for x in self.enemies(turn-1)}

        # Players to examine are non-exploding ones.
        old_players = [y for y in self.players(turn-1) if
                   y.location not in self.turns[turn-1].explode_locs]
        new_players_id = {y.robot_id: y for y in self.players(turn)}

        # Find players hit with abnormal damage, or 7 w/ guarding
        for y in old_players:
            num_nearby_enemies = sum (1 for loc in rg.locs_around(y.location)
                                      if loc in old_enemiesl)
            max_norm_dmg = 10*num_nearby_enemies
            new_hp = (new_players_id[y.robot_id].hp if
                        y.robot_id in new_players_id else 0)
            hp_diff = y.hp - new_hp
            guarded = y.location in self.turns[turn-1].guard_locs
            if ((hp_diff == 7 and guarded) or hp_diff > max_norm_dmg):
                print "{0} hit with {1} damage.".format(y, hp_diff)
                # find culprit(s)
                candidates = [old_enemiesl[loc] for loc in
                              rg.locs_around(y.location)
                              if loc in old_enemiesl]
                if len(candidates) == 1:
                    self._record_explosion_point(candidates[0])
                elif len(candidates) > 1:
                    for e in candidates:
                        l = e.location
                        if self.exploded in self.reconstructed_info[l].actions:
                            self._record_explosion_point(old_enemiesl[l])
Example #7
0
    def _get_danger(self, game, loc):
        """Returns the danger of the given location as an integer between
        1 and 10.
        """
        baseline = 5
        if 'spawn' in rg.loc_types(loc):
            baseline += 2
        
        enemy_bots = self._get_enemies(game, loc)
        for enemy_loc, bot in enemy_bots:
            if enemy_loc in rg.locs_around(loc):
                baseline = 10 # Can't go here

            for adj in rg.locs_around(loc):
                if adj in rg.locs_around(enemy_loc):
                    baseline += (bot.hp - self.hp) // 10

        friends = self._get_friends(game, loc)
        for friend_loc, bot in friends:
            if friend_loc in rg.locs_around(loc):
                baseline = 10 # Can't go here

        if baseline < 1:
            baseline = 1
        elif baseline > 10:
            baseline = 10

        return baseline
Example #8
0
    def act(self, game):
        # Borrowed sets of sets from github.com/ramk13
        all_locs = {(x, y) for x in xrange(19) for y in xrange(19)}
        spawn = {loc for loc in all_locs if 'spawn' in rg.loc_types(loc)}
        obstacle = {loc for loc in all_locs if 'obstacle' in rg.loc_types(loc)}
        team = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
        enemy = set(game.robots) - team
        adjacent = set(rg.locs_around(self.location)) - obstacle
        adjacent_enemy = adjacent & enemy
        safe = adjacent - adjacent_enemy - spawn - team

        north = {loc for loc in team if loc[1] > 9 and loc[0] > 9}
        east = {loc for loc in team if loc[1] <= 9 < loc[0]}
        west = {loc for loc in team if loc[1] <= 9 and loc[0] <= 9}
        south = team - north - east - west

        x, y = int(sum(x for x, y in north if self)/len(north)), int(sum(y for x, y in north)/len(north))
        sx, sy = int(sum(x for x, y in south)/len(south)), int(sum(y for x, y in south)/len(south))
        if self.location in ((nx, ny), (sx, sy)) or rg.locs_around(self.location) in ((nx, ny), (sx, sy)):
            if self.location not in spawn:
                return ['guard']
        if len(adjacent_enemy) >= 3:
            return ['suicide']
        if self.hp < 9 and adjacent_enemy:
            return ['suicide']
        if adjacent_enemy:
            return ['attack', min(adjacent_enemy, key=lambda x: rg.dist(x, self.location))]
        if safe:
            if self.location in north:
                return ['move', rg.toward(self.location, (nx, ny))]
            else:
                return ['move', rg.toward(self.location, (sx, sy))]
        return ['guard']
Example #9
0
    def act(self, game):

        global runda_numer, wybrane_pola
        if game.turn != runda_numer:
            runda_numer = game.turn
            wybrane_pola = set()

        # jeżeli się ruszamy, zapisujemy docelowe pole
        def ruszaj(loc):
            wybrane_pola.add(loc)
            return ['move', loc]

        # jeżeli stoimy, zapisujemy zajmowane miejsce
        def stoj(act, loc=None):
            wybrane_pola.add(self.location)
            return [act, loc]

        # wyznaczamy zbiory różnych pól na planszy
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
        zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
        druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
        wrogowie = set(game.robots) - druzyna
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
        # bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna
        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - \
                     wejscia - druzyna - wybrane_pola

        def mindist(bots, loc):
            return min(bots, key=lambda x: rg.dist(x, loc))

        def minhp(bots):
            return min(bots, key=lambda x: game.robots[x].hp)

        if wrogowie:
            najblizszy_wrog = mindist(wrogowie,self.location)
        else:
            najblizszy_wrog = rg.CENTER_POINT

        ruch = ['guard']

        if self.location in wejscia:
            if bezpieczne:
                ruch = ['move',  mindist(bezpieczne, rg.CENTER_POINT)]
        elif sasiednie_wrogowie:
            if 9*len(sasiednie_wrogowie) < self.hp:
                ruch = stoj('attack',minhp(sasiednie_wrogowie.pop()))
            elif bezpieczne:
                ruch = ruszaj(mindist(bezpieczne, rg.CENTER_POINT))
            else:
                ruch = stoj('suicide')
        elif sasiednie_wrogowie2 and self.location not in wybrane_pola:
            ruch = ['attack', sasiednie_wrogowie2.pop()]
        elif bezpieczne:
            ruch = ruszaj(mindist(bezpieczne, najblizszy_wrog))


        return ruch
Example #10
0
    def act(self, game):

        # wyznaczamy zbiory różnych pól na planszy
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
        zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
        druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
        wrogowie = set(game.robots) - druzyna
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna

        def mindist(bots, loc):
            return min(bots, key=lambda x: rg.dist(x, loc))

        ruch = ['guard']

        if self.location in wejscia:
            if bezpieczne:
                ruch = ['move',  mindist(bezpieczne, rg.CENTER_POINT)]

        if self.location == rg.CENTER_POINT:
            ruch = ['guard']

        if sasiednie_wrogowie:
            if 9*len(sasiednie_wrogowie) < self.hp:
                ruch = ['attack', sasiednie_wrogowie.pop()]

        if sasiednie_wrogowie2:
            ruch = ['attack', sasiednie_wrogowie2.pop()]

        return ruch
Example #11
0
 def getNearbyOpenLocations(self, loc):
     locs = set(rg.locs_around(loc, filter_out=('invalid', 'obstacle', 'spawn')))
     locs = locs - self.blocked_move_locs
     if len(locs) == 0:
         locs = set(rg.locs_around(loc, filter_out=('invalid', 'obstacle')))
         locs = locs - self.blocked_move_locs
     return list(locs)
Example #12
0
 def getNearbyOpenLocations(self, loc):
     locs = set(
         rg.locs_around(loc, filter_out=('invalid', 'obstacle', 'spawn')))
     locs = locs - self.blocked_move_locs
     if len(locs) == 0:
         locs = set(rg.locs_around(loc, filter_out=('invalid', 'obstacle')))
         locs = locs - self.blocked_move_locs
     return list(locs)
Example #13
0
    def act(self, game):

        # wszystkie pola
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        # punkty wejścia
        wejscia = {poz for poz in wszystkie if 'spawn' in rg.loc_types(poz)}
        # pola zablokowane
        zablokowane = {
            poz
            for poz in wszystkie if 'obstacle' in rg.loc_types(poz)
        }
        # pola zajęte przez nasze roboty
        przyjaciele = {
            poz
            for poz in game.robots
            if game.robots[poz].player_id == self.player_id
        }
        # pola zajęte przez wrogów
        wrogowie = set(game.robots) - przyjaciele
        # pola sąsiednie
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        # pola sąsiednie zajęte przez wrogów
        wrogowie_obok = sasiednie & wrogowie
        wrogowie_obok2 = {
            poz
            for poz in sasiednie if (set(rg.locs_around(poz)) & wrogowie)
        } - przyjaciele
        # pola bezpieczne
        bezpieczne = sasiednie - wrogowie_obok - wejscia - przyjaciele

        # funkcja znajdująca najsłabszego wroga obok z podanego zbioru (bots)
        def minhp(bots):
            return min(bots, key=lambda x: game.robots[x].hp)

        # działanie domyślne:
        ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]

        # jeżeli jesteś w punkcie wejścia, opuść go
        if self.location in wejscia:
            ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]

        # jeżeli jesteś w środku, broń się
        if self.location == rg.CENTER_POINT:
            ruch = ['guard']

        # jeżeli obok są przeciwnicy, atakuj, o ile to bezpieczne,
        # najsłabszego wroga
        if wrogowie_obok:
            if 9 * len(wrogowie_obok) >= self.hp:
                if bezpieczne:
                    ruch = ['move', bezpieczne.pop()]
            else:
                ruch = ['attack', minhp(wrogowie_obok)]

        if wrogowie_obok2:
            ruch = ['attack', wrogowie_obok2.pop()]

        return ruch
Example #14
0
 def test_locs_around(self):
     locs = set(rg.locs_around((0,0)))
     assert locs == set(((0, 1), (1, 0), (0, -1), (-1, 0)))
     
     locs = set(rg.locs_around((10, 100)))
     assert locs == set(((10, 101), (11, 100), (10, 99), (9, 100)))
     
     locs = set(rg.locs_around((0,0), filter_out=["invalid"]))
     assert locs == set(((0, 1), (1, 0)))
Example #15
0
 def places_to_go(from_loc, occupied_space_list):
     ret_list = []
     nearby_places = rg.locs_around(from_loc , filter_out=('invalid', 'obstacle'))
     if(game['turn']%10 == 0 or game['turn']%10 == 9):
         nearby_places = rg.locs_around(from_loc , filter_out=('invalid', 'obstacle', 'spawn'))
     for targ in nearby_places:
         if not occupied(targ,occupied_space_list):
             ret_list.append(targ)
     return ret_list
Example #16
0
 def places_to_go(from_loc, occupied_space_list):
     ret_list = []
     nearby_places = rg.locs_around(from_loc , filter_out=('invalid', 'obstacle'))
     if(game['turn']%10 == 0 or game['turn']%10 == 9):
         nearby_places = rg.locs_around(from_loc , filter_out=('invalid', 'obstacle', 'spawn'))
     for targ in nearby_places:
         if not occupied(targ,occupied_space_list):
             ret_list.append(targ)
     return ret_list
Example #17
0
 def open_locs_around(self, loc, spawn=True):
     locs = []
     if spawn:
         locs = rg.locs_around(loc, filter_out=('invalid', 'obstacle', 'spawn'))
     else:
         locs = rg.locs_around(loc, filter_out=('invalid', 'obstacle'))
     for i in locs:
         if i in self.enemy_bots or i in self.planned_move_locs:
             locs.remove(i)
     return locs
Example #18
0
 def open_locs_around(self, loc, spawn=True):
     locs = []
     if spawn:
         locs = rg.locs_around(loc,
                               filter_out=('invalid', 'obstacle', 'spawn'))
     else:
         locs = rg.locs_around(loc, filter_out=('invalid', 'obstacle'))
     for i in locs:
         if i in self.enemy_bots or i in self.planned_move_locs:
             locs.remove(i)
     return locs
Example #19
0
    def act(self, game):

        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        wejscia = {poz for poz in wszystkie if 'spawn' in rg.loc_types(poz)}
        zablokowane = {
            poz
            for poz in wszystkie if 'obstacle' in rg.loc_types(poz)
        }
        druzyna = {
            poz
            for poz in game.robots
            if game.robots[poz].player_id == self.player_id
        }
        wrogowie = set(game.robots) - druzyna
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {
            poz
            for poz in sasiednie if (set(rg.locs_around(poz)) & wrogowie)
        } - druzyna
        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna

        def mindist(bots, poz):
            return min(bots, key=lambda x: rg.dist(x, poz))

        if wrogowie:
            najblizszy_wrog = mindist(wrogowie, self.location)
        else:
            najblizszy_wrog = rg.CENTER_POINT

        # działanie domyślne:
        ruch = ['guard']

        if self.location in wejscia:
            if bezpieczne:
                ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]

        if self.location == rg.CENTER_POINT:
            ruch = ['guard']

        if sasiednie_wrogowie:
            if 9 * len(sasiednie_wrogowie) >= self.hp:
                if bezpieczne:
                    ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
            else:
                ruch = ['attack', sasiednie_wrogowie.pop()]

        if sasiednie_wrogowie2:
            ruch = ['attack', sasiednie_wrogowie2.pop()]

        if bezpieczne:
            ruch = ['move', mindist(bezpieczne, najblizszy_wrog)]

        return ruch
Example #20
0
 def isTrapped(self, loc, with_spawn=False):
     trap = True
     nearby = []
     if with_spawn:
         nearby = rg.locs_around(loc, filter_out=('invalid','obstacle','spawn'))
     else:
         nearby = rg.locs_around(loc, filter_out=('invalid','obstacle'))
     for near in nearby:
         if near not in self.all_bots:
             trap = False
     return trap
Example #21
0
 def panic(include_suicide):
     poss = []
     ar = rg.locs_around(curr, filter_out=('invalid','obstacle'))
     if include_suicide:
         ar = rg.locs_around(curr, filter_out=('invalid','obstacle','spawn'))
     for around in ar:
         if around not in game_bots:
             poss.append(around)
     if len(poss) == 0:
         return None
     return poss[random.randint(0, len(poss) - 1)]
Example #22
0
    def act(self, game):
        global runda_numer, wybrane_ruchy
        if game.turn != runda_numer:
            runda_numer = game.turn
            wybrane_ruchy = set()

        def ruszaj(loc):
            wybrane_ruchy.add(loc)
            return ['move', loc]

        def stoj(act, loc=None):
            wybrane_ruchy.add(self.location)
            return [act, loc]

        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
        zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
        druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
        wrogowie = set(game.robots)-druzyna

        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna - wybrane_ruchy

        def mindist(bots, loc):
            return min(bots, key=lambda x: rg.dist(x, loc))

        if wrogowie:
            najblizszy_wrog = mindist(wrogowie,self.location)
        else:
            najblizszy_wrog = rg.CENTER_POINT

        # akcja domyślna, którą nadpiszemy, jak znajdziemy coś lepszego
        ruch = ['guard']

        if self.location in wejscia:
            if bezpieczne:
                ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
        elif sasiednie_wrogowie:
            if 9*len(sasiednie_wrogowie) >= self.hp:
                if bezpieczne:
                    ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
            else:
                ruch = ['attack', sasiednie_wrogowie.pop()]
        elif sasiednie_wrogowie2 and self.location not in wybrane_ruchy:
            #ruch = ['attack', sasiednie_wrogowie2.pop()]
            if sasiednie_wrogowie:
                ruch = stoj('attack',sasiednie_wrogowie.pop())
        elif bezpieczne:
            #ruch = ['move', mindist(bezpieczne, najblizszy_wrog)]
            ruch = ruszaj(mindist(bezpieczne, najblizszy_wrog))
        return ruch
Example #23
0
 def guessShot():
     for potentialShot in rg.locs_around(self.location, filter_out=('invalid', 'obstacle')):
         allyCount = 0
         enemyCount = 0
         if potentialShot not in game['robots']:
             for enemy in rg.locs_around(potentialShot, filter_out=('invalid', 'obstacle')):
                 if enemy in game['robots']:
                     if game['robots'][enemy].player_id != self.player_id:
                         enemyCount += 1
             if enemyCount > 0:
                 return ['attack', potentialShot]
     return ['attack', rg.toward(self.location, closestEnemy)]
Example #24
0
    def act(self, game):

        # wszystkie pola
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        # punkty wejścia
        wejscia = {poz for poz in wszystkie if 'spawn' in rg.loc_types(poz)}
        # pola zablokowane
        zablokowane = {
            poz
            for poz in wszystkie if 'obstacle' in rg.loc_types(poz)
        }
        przyjaciele = {
            poz
            for poz in game.robots
            if game.robots[poz].player_id == self.player_id
        }
        # pola zajęte przez wrogów
        wrogowie = set(game.robots) - przyjaciele
        # pola sąsiednie
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        # pola sąsiednie zajęte przez wrogów
        wrogowie_obok = sasiednie & wrogowie
        wrogowie_obok2 = {
            poz
            for poz in sasiednie if (set(rg.locs_around(poz)) & wrogowie)
        } - przyjaciele
        # pola bezpieczne
        bezpieczne = sasiednie - wrogowie_obok - wejscia - przyjaciele

        # działania domyslne:
        ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]
        # jeżeli jeteś wpkt wejścia opuść go
        if self.location in wejscia:
            ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]
        # jeżeli jesteś w środku broń się
        if self.location == rg.CENTER_POINT:
            ruch = ['guard']

        # jeżeli obok są przeciwnicy, atakuj o ile to bezpieczne
        if wrogowie_obok:
            if 9 * len(wrogowie_obok) >= self.hp:
                if bezpieczne:
                    ruch['move', bezpieczne.pop()]
            else:
                ruch = ['attack', wrogowie_obok.pop()]

        if wrogowie_obok2:
            ruch = ['attack', wrogowie_obok2.pop()]

        return ruch
Example #25
0
    def act(self, game):

        # wszystkie pola
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        # punkty wejścia
        wejscia = {poz for poz in wszystkie if 'spawn' in rg.loc_types(poz)}
        # pola zablokowane
        zablokowane = {poz for poz in wszystkie if 'obstacle' in rg.loc_types(poz)}
        # pola zajęte przez nasze roboty
        przyjaciele = {poz for poz in game.robots if game.robots[poz].player_id == self.player_id}
        # pola zajęte przez wrogów
        wrogowie = set(game.robots) - przyjaciele
        # pola sąsiednie
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        # pola sąsiednie zajęte przez wrogów
        wrogowie_obok = sasiednie & wrogowie
        wrogowie_obok2 = {poz for poz in sasiednie if (set(rg.locs_around(poz)) & wrogowie)} - przyjaciele
        # pola bezpieczne
        bezpieczne = sasiednie - wrogowie_obok - wejscia - przyjaciele

        # funkcja znajdująca najsłabszego wroga obok z podanego zbioru (bots)
        def minhp(bots):
            return min(bots, key=lambda x: game.robots[x].hp)

        # działanie domyślne:
        ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]

        # jeżeli jesteś w punkcie wejścia, opuść go
        if self.location in wejscia:
            ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]

        # jeżeli jesteś w środku, broń się
        if self.location == rg.CENTER_POINT:
            ruch = ['guard']

        # jeżeli obok są przeciwnicy, atakuj, o ile to bezpieczne,
        # najsłabszego wroga
        if wrogowie_obok:
            if 9*len(wrogowie_obok) >= self.hp:
                if bezpieczne:
                    ruch = ['move', bezpieczne.pop()]
            else:
                ruch = ['attack', minhp(wrogowie_obok)]

        if wrogowie_obok2:
            ruch = ['attack', wrogowie_obok2.pop()]

        return ruch
Example #26
0
    def generate_move(self, robot):
        '''
        Entry-point for turn generation
        '''
        if robot.hp <= FLEE_HP_THRESHHOLD:
            return self._flee(robot)

        if Utils.is_spawn(robot.location) and Utils.new_robots_spawning(self.turn + 1):
            for loc in rg.locs_around(robot.location, filter_out=('invalid', 'obstacle', 'spawn')):
                return ['move', loc]

        enemyId = 0 if robot.player_id == 1 else 1
        closestEnemy = self._closest_robot(enemyId, robot.location)

        if closestEnemy != None:
            if rg.wdist(robot.location, closestEnemy.location) <= 1:
                return ['attack', closestEnemy.location]
            else:
                path = self._cooperative_shortest_path(self.graph, robot.location, closestEnemy.location)
                if path == None:
                    return ['guard']
                else:
                    self._commit_path_to_future_locations(path)
                    return ['move', path[1]]

        # move toward the center
        path = self._cooperative_shortest_path(self.graph, robot.location, rg.CENTER_POINT)
        if path == None:
            return ['move', rg.toward(robot.location, rg.CENTER_POINT)]
        else:
            self._commit_path_to_future_locations(path)
            return ['move', path[1]]
Example #27
0
 def znajdz_wrogow_obok(self, game, wrogowie, bezpieczne):
     for poz in rg.locs_around(self.location, filter_out=('invalid', 'obstacle')):
         if game.robots.get(poz) and \
            game.robots[poz].player_id != self.player_id:
                wrogowie.append(poz)
         elif not czy_wejscie(poz):
             bezpieczne.append(poz)
Example #28
0
    def act(self, game):
        # if we're in the center, stay put
        if self.location == rg.CENTER_POINT:
            return ['guard']

        num_enemies_near = sum([ pt in self.enemy_bot_locations(game) for pt in rg.locs_around(self.location)])
        if num_enemies_near > 1 and self.hp < 20:
            return ['suicide']

        # 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]

        # move toward the center
        dist_to_center = rg.wdist(self.location, rg.CENTER_POINT)
        if dist_to_center > 5:
            next_location = rg.toward(self.location, rg.CENTER_POINT)
        else:
            next_location = self.random_location()
        
        if next_location in game.robots:
            return ['guard']

        return ['move', next_location]
Example #29
0
 def in_danger(self,game):
   if 'spawn' in rg.loc_types(self.location):
     return True
   for location in rg.locs_around(self.location):
     if location in game['robots']:
       return True
   return False
Example #30
0
 def nearby_robots(self, center, allies=True):
     if not center:
         return []
     locs = rg.locs_around(center)
     return [bot for loc, bot in self.g['robots'].items()
             if loc in locs and
             self.on_team(bot) == allies]
Example #31
0
    def find_path(self, game):
        location = self.location

        if location == rg.CENTER_POINT:
            return ['guard']

        locations_around = rg.locs_around(location,
                                          filter_out=('invalid', 'obstacle'))

        locations_around.append(location)
        rated_locations = []

        for possible_location in locations_around:
            center_dist = rg.wdist(possible_location, rg.CENTER_POINT)
            rated_locations.append((
                self.location_score(self.location, possible_location, game),
                -center_dist,
                possible_location
            ))

        rated_locations.sort(reverse=True)

        selected_location = rated_locations[0][2]

        if selected_location != location:
            return ['move', selected_location]
        else:
            return ['guard']
Example #32
0
    def act(self, game):
        my_team = self.player_id
        if 'spawn' in rg.loc_types(self.location):
            return ['move', rg.toward(self.location, rg.CENTER_POINT)]
        else:
            # Get the nearby locations
            near_locations = rg.locs_around(self.location)
            # For each location see if there is a robot there or not...
            for loc in near_locations:
                try:
                    robot_location = game.robots[loc]
                    # There is...
                    # If it is our own robot, just move to the center one step. Stop moving when we reach the center.
                    if game.robots[loc][
                            'player_id'] == my_team and self.location != rg.CENTER_POINT:
                        return [
                            'move',
                            rg.toward(self.location, rg.CENTER_POINT)
                        ]
                    elif game.robots[loc]['player_id'] != my_team:
                        return ['attack', loc]
                except KeyError:
                    # There are no robots there...
                    pass

        return ['guard']
Example #33
0
 def znajdz_wrogow_obok(self, game):
     wrogowie = []
     for poz in rg.locs_around(self.location, filter_out=('invalid', 'obstacle')):
         if game.robots.get(poz) and \
            game.robots[poz].player_id != self.player_id:
                wrogowie.append(poz)
     return wrogowie
	def __init__(self, robot, game):

		self.robot = robot
		self.game = game
		self.current_loc_types = rg.loc_types(robot.location)

		self.unobstructed_locs = []
		self.normal_unobstructed_locs = []
		self.safe_locs = []

		self.immediate_friends = []
		self.immediate_enemies = []
		
		valid_and_wall_locs = rg.locs_around(robot.location, filter_out='invalid')

		self.valid_locs = []
		for vwloc in valid_and_wall_locs:
			if not 'obstacle' in rg.loc_types(vwloc):
 				self.unobstructed_locs.append(vwloc)
 				self.valid_locs.append(vwloc)
 			elif vwloc in self.game.robots:
 				# valid locs INCLUDES robots
 				self.valid_locs.append(vwloc)
 
		self.immediate_enemies = self.enemies_around(self.robot.location, self.robot.player_id)
		self.immediate_friends = self.friends_around(self.robot.location, self.robot.player_id, self.robot.location)

 		for unobloc in self.unobstructed_locs:
 			if not 'spawn' in rg.loc_types(unobloc):
 				self.normal_unobstructed_locs.append(unobloc)

 			if not self.enemies_around(unobloc, robot.player_id):
				self.safe_locs.append(unobloc)
Example #35
0
 def panic(self, currLoc):
     locs = rg.locs_around(currLoc, filter_out=('invalid','obstacle','spawn'))
     target = currLoc
     for loc in locs:
         if self.isEmptySpace(loc) is True:
             target = loc
     return target
Example #36
0
 def spawn(self, game, current_return):
     if current_return != ['empty']:
         return current_return
     #If bot is in spawn, determine how to move out.
     if rg.loc_types(self.location) == 'spawn':
         possible_locations = rg.locs_around(self.location,
                                             filter_out=('invalid',
                                                         'obstacle',
                                                         'spawn'))
         enemy_locs = []
         for locs in possible_locations:
             if locs in game.robots and game.robots[
                     locs].player_id != self.player_id:
                 enemy_locs.append(locs)
         for enemy in enemy_locs:
             if enemy.hp < 9:
                 return ['attack', enemy]
             elif enemy in possible_locations:
                 possible_locations.remove(enemy)
         best_option = [100, (0, 0)]
         for locs in possible_locations:
             current = [rg.wdist(locs, rg.CENTER_POINT), locs]
             if current[0] <= best_option[0]:
                 best_option = current
         return ['move', best_option[1]]
     return current_return
Example #37
0
    def act(self, game):
        # Find nearest enemy
        enemies = {}
        nearest_enemy = (1000000, rg.CENTER_POINT)
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                enemies[loc] = bot
                distance = rg.dist(loc, self.location)
                if distance < nearest_enemy[0]:
                    nearest_enemy = (distance, loc)

        # If nearest enemy is next to us, ATTACK or KABOOM!
        if nearest_enemy[0] <= 1:
            potential_suicide_damage = 0
            for loc in rg.locs_around(self.location):
                if loc in enemies:
                    potential_suicide_damage += min(15, enemies[loc].hp)
            if self.hp < potential_suicide_damage:
                return ['suicide']
            else:
                return ['attack', nearest_enemy[1]]

        # If we cannot move, defend.
        desired_move = rg.toward(self.location, nearest_enemy[1])
        if rg.loc_types(desired_move) in ['obstacle', 'invalid']:
            return ['guard']

        # Otherwise, advance on the enemy without mercy
        return ['move', desired_move]
Example #38
0
 def find_five_points(loc):
     self._five_points = [loc]
     #self._five_points.append(loc)
     self._new_points = rg.locs_around(loc, filter_out=('invalid', 'obstacle'))
     for point in self._new_points:
         self._five_points.append(point)
     return self._five_points
Example #39
0
    def act(self, game):

        # When a new turn is started need to clear the new_locs list.
        if self.last_turn != game.turn:
            self.new_locs = []
            self.last_turn = game.turn


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


        random.seed()
        # Otherwise move around pick a direction that can randomly
        # move to and move there.
        moves = rg.locs_around(self.location, filter_out=('invalid', 'obstacle'))
        moves = [loc for loc in moves if loc not in self.new_locs]

        if len(moves) > 0:
            choice = random.choice(moves)
            self.new_locs.append(choice)
            return ['move', choice]

        self.new_locs.append(self.location)
        return ['guard']
Example #40
0
    def attack(self, game, current_return):
        if current_return != ['empty']:
            return current_return
        possible_locations = rg.locs_around(self.location,
                                            filter_out=('invalid', 'obstacle',
                                                        'spawn'))
        enemy_locs = []
        enemy_num = 0
        for locs in possible_locations:
            if locs in game.robots and game.robots[
                    locs].player_id != self.player_id:
                enemy_num += 1
                enemy_locs.append(locs)
        #Once we have a list of enemies, we can follow a process to determine how to deal with them.
        """ if 1 enemy:
            if myhealth > enemyhealth:
            attack
            if myhealth < enemyhealth:
            if they have less than 15, suicide
            else back away
            if 2 or more enemy:
            if both less than 15 and mine less than 20, suicide
            else back away
            else go to move """

        for enemy in enemy_locs:
            return ['attack', enemy]

            #Need to flesh out attack strategy
            if enemy_num == 1:
                return ['attack', enemy]
        return current_return
Example #41
0
 def call_suicide(self, action_table):
     self.hp = 0
     self.call_attack(self.location,
                      action_table,
                      damage=settings.suicide_damage)
     for loc in rg.locs_around(self.location):
         self.call_attack(loc, action_table, damage=settings.suicide_damage)
    def act(self, game):

        # When a new turn is started need to clear the new_locs list.
        if self.last_turn != game.turn:
            self.new_locs = []
            self.last_turn = game.turn

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

        random.seed()
        # Otherwise move around pick a direction that can randomly
        # move to and move there.
        moves = rg.locs_around(self.location,
                               filter_out=('invalid', 'obstacle'))
        moves = [loc for loc in moves if loc not in self.new_locs]

        if len(moves) > 0:
            choice = random.choice(moves)
            self.new_locs.append(choice)
            return ['move', choice]

        self.new_locs.append(self.location)
        return ['guard']
Example #43
0
 def act(self, game):
   robots = game['robots']
   locs = rg.locs_around(self.location, filter_out=('invalid', 'obstacle'))
   
   enemies = [loc for loc in locs if loc in robots and robots[loc]['player_id'] != self.player_id]
   if enemies: ## attack weakest
       loc = sorted(enemies, key=lambda x: robots[x]['hp'])[0]
       return ['attack', loc]
   
   ## so no enemy nearby, walk around randomly but prefer non-spawn points
   
   ## filter out my own occupied spots
   locs = [loc for loc in locs if loc not in robots]
   
   ## empty non spawn points?
   non_spawn = [loc for loc in locs if 'spawn' not in rg.loc_types(loc)]
   if non_spawn:
       loc = random.choice(non_spawn)
       return ['move', loc]
       
   spawn = [loc for loc in locs if 'spawn' in rg.loc_types(loc)]
   if spawn:
       loc = random.choice(spawn)
       return ['move', loc]
       
   ## no more options
   return ['guard']
Example #44
0
 def local_enemies(self, game):
     locs = rg.locs_around(self.location)
     bots = {}
     for loc, bot in game.robots.iteritems():
         if bot.player_id != self.player_id and loc in self.local_spaces():
             bots[loc] = bot
     return bots
Example #45
0
    def escape_spawn_trap_move(self, game):
        if 'spawn' in rg.loc_types(self.location):
            locs = [x for x in rg.locs_around(self.location) if
                    self.is_empty_loc(game, x)]
            free_locs = [x for x in locs if 'spawn' not in rg.loc_types(x)]
            safe_locs = [x for x in locs if self.is_safe_from_attacks(game, x)]
            safe_and_free_locs = [x for x in free_locs if x in safe_locs]

            # Try moving away first, even if may get hit.
            if len(safe_and_free_locs) > 0:
                return ['move', random.choice(safe_and_free_locs)]
            elif len(safe_locs) > 0:
                return ['move', random.choice(safe_locs)]
            elif len(free_locs) > 0:
                return ['move', random.choice(free_locs)]
            elif len(locs) > 0:
                return ['move', random.choice(locs)]
            # No where to move.
            else:
                # Todo: for friendlies, can tell them to gtfo out lol.
                # Todo: find a route, instead of just moving back n forth lol

                # Gonna die anyways, explode and cause some damage!
                # Enemies likely to guard. Some may move but hard to tell.
                if self.is_spawn_reset(game):
                    return ['suicide']
                # Else, go to some other behaviour
                return False
Example #46
0
 def collided(self, loc, game):
     """
     Checks whether robots collided at loc in the last turn
     """
     # TODO: Improve collision detection.
     # This method results in false positives because downhill last turn
     # may not be downhill this turn.
     # Sometimes it also results in false negatives. Cause unknown. Perhaps
     # it is not being called.
     if not self.last_game:
         # This is the first turn.
         return False
     collided_friend = collided_enemy = False
     adjacent = rg.locs_around(loc)
     for adj in adjacent:
         if (
             adj in game['robots'] and
             adj in self.last_game['robots'] and
             game['robots'][adj].player_id == self.last_game['robots'][adj]['player_id'] and
             game['robots'][adj].hp == self.last_game['robots'][adj]['hp'] - settings.collision_damage
         ):
             if game['robots'][adj].player_id == self.player_id:
                 collided_friend = True
             else:
                 collided_enemy = True
             if collided_friend and collided_enemy:
                 if DEBUG:
                     print('Avoided collision at {}'.format(loc))
                 return True
     return False
 def coward(self, game):
     # First, make sure you are not in a spawn point
     if 'spawn' in rg.loc_types(self.location):
         #Move out of spawn point!
         return ['move', rg.toward(self.location, rg.CENTER_POINT)]
     
     # second, make sure you are not next to an enemy
     locations = rg.locs_around(self.location, filter_out=('invalid', 'obstacle'))
     enemies = []
     for l in locations:
         bot = game['robots'].get(l)
         if bot and bot['player_id'] != self.player_id:
             enemies.append(bot)
     if enemies:
         #Find a safe place!
         for l in locations:
             if not game['robots'].get(l):
                 # unoccupied spot!
                     return ['move', l]
         else:
             # surrounded!
             if self.hp < rg.settings.attack_range[1] * len(enemies):
                 return ['suicide']
             else:
                 target = min(enemies, key=lambda x: x['hp'])
                 return ['attack', target['location']]
     # finally, just chill out.
     return ['guard']
Example #48
0
    def attack(self, game, current_return):
        if current_return != ['empty']:
            return current_return
        possible_locations = rg.locs_around(self.location, filter_out = ('invalid', 'obstacle', 'spawn'))
        enemy_locs = []
        enemy_num = 0
        for locs in possible_locations:
            if locs in game.robots and game.robots[locs].player_id != self.player_id:
                enemy_num += 1
                enemy_locs.append(locs)
        #Once we have a list of enemies, we can follow a process to determine how to deal with them.
        """ if 1 enemy:
            if myhealth > enemyhealth:
            attack
            if myhealth < enemyhealth:
            if they have less than 15, suicide
            else back away
            if 2 or more enemy:
            if both less than 15 and mine less than 20, suicide
            else back away
            else go to move """

        for enemy in enemy_locs:
            return ['attack', enemy]

        #Need to flesh out attack strategy
            if enemy_num == 1:
                return ['attack', enemy]
        return current_return
Example #49
0
    def act(self, game):
        center = rg.CENTER_POINT
        enemy_bots = [
            b for b in game.robots.values() if b.player_id != self.player_id
        ]
        target = min(enemy_bots,
                     key=lambda bot: rg.wdist(bot.location, center))

        adjacent_bots = []
        for enemy in enemy_bots:
            if rg.wdist(enemy.location, self.location) == 1:
                adjacent_bots.append(enemy)
        if len(adjacent_bots) > self.hp / 9:
            return ['suicide']
        elif adjacent_bots:
            return ['attack', min(adjacent_bots, key=lambda b: b.hp).location]

        adj = rg.locs_around(target.location,
                             filter_out=('invalid', 'obstacle'))
        closest_locs = min(rg.wdist(loc, self.location) for loc in adj)
        dests = [
            loc for loc in adj if rg.wdist(loc, self.location) == closest_locs
        ]
        dest = random.choice(dests)
        if rg.wdist(target.location, self.location) == 1:
            return ['attack', target.location]
        else:
            return ['move', rg.toward(self.location, dest)]
Example #50
0
    def adjacents(self,
                  location=None,
                  filter_id=None,
                  filter_empty=False,
                  only_empty=False,
                  only_id=False):
        if location == None:
            location = self.location

        locs = rg.locs_around(location, filter_out=('invalid', 'obstacle'))

        if only_empty != None:
            return [loc for loc in locs if loc not in self.robots]

        if only_id != None:
            return [
                loc for loc in locs if loc in self.robots
                and self.robots[loc]['player_id'] == only_id
            ]

        if filter_empty != None:
            locs = [loc for loc in locs if loc in self.robots]

        if filter_id != None:
            locs = [loc for loc in locs if loc not in self.robots \
                or self.robots[loc]['player_id'] != filter_id]

        return locs
Example #51
0
 def validate_action(self, formatted_action, game):
     if len(formatted_action) > 1:
         if formatted_action[1] == None:
             return False
         if formatted_action[0] == "move":
             return formatted_action[1] in rg.locs_around(self.location)
     return True #placeholder
Example #52
0
    def act(self, game):
        bestDistance = 999
        bestLoc = (0, 0)
        otherPlaces = rg.locs_around(self.location,
                                     filter_out=('invalid', 'obstacle'))
        for loc, bot in game['robots'].iteritems():
            if bot.player_id != self.player_id:
                if rg.wdist(loc, self.location) < bestDistance:
                    bestDistance = rg.dist(loc, self.location)
                    bestLoc = loc
        if game['robots'][self.location].hp <= 10:
            away = tuple(
                map(lambda x, y: x - y, rg.toward(self.location, bestLoc),
                    self.location))
            move = tuple(map(lambda x, y: x - y, self.location, away))
            goodPlaces = rg.locs_around(self.location,
                                        filter_out=('invalid', 'obstacle',
                                                    'spawn'))
            if move in goodPlaces:
                return ['move', move]
            for loc in rg.locs_around(self.location,
                                      filter_out=('invalid', 'obstacle')):
                if loc in game['robots']:
                    if game['robots'][loc].player_id != self.player_id:
                        return ['suicide']

            else:
                return ['guard']
        for loc, bot in game['robots'].iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    if loc in otherPlaces:
                        return ['attack', loc]
        if rg.dist(bestLoc, self.location) <= enemyDistance:
            if rg.toward(self.location, bestLoc) in otherPlaces:
                return ['move', rg.toward(self.location, bestLoc)]

        # otherwise clump up
        for loc, bot in game['robots'].iteritems():
            if bot.player_id == self.player_id:
                if rg.wdist(loc, self.location) <= allyDistance:
                    if loc in otherPlaces:
                        return ['move', rg.toward(self.location, loc)]
        if self.location == rg.CENTER_POINT:
            return ['guard']
        if rg.toward(self.location, rg.CENTER_POINT) in otherPlaces:
            return ['move', rg.toward(self.location, rg.CENTER_POINT)]
Example #53
0
    def act(self, game):

        # wyznaczamy zbiory różnych pól na planszy
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
        zablokowane = {
            loc
            for loc in wszystkie if 'obstacle' in rg.loc_types(loc)
        }
        druzyna = {
            loc
            for loc in game.robots
            if game.robots[loc].player_id == self.player_id
        }
        wrogowie = set(game.robots) - druzyna
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {
            loc
            for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)
        } - druzyna
        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna

        def mindist(bots, loc):
            return min(bots, key=lambda x: rg.dist(x, loc))

        if wrogowie:
            najblizszy_wrog = mindist(wrogowie, self.location)
        else:
            najblizszy_wrog = rg.CENTER_POINT

        ruch = ['guard']

        if self.location in wejscia:
            if bezpieczne:
                ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
        elif sasiednie_wrogowie:
            if 9 * len(sasiednie_wrogowie) < self.hp:
                ruch = ['attack', sasiednie_wrogowie.pop()]
            elif bezpieczne:
                ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
        elif sasiednie_wrogowie2:
            ruch = ['attack', sasiednie_wrogowie2.pop()]
        elif bezpieczne:
            ruch = ['move', mindist(bezpieczne, najblizszy_wrog)]

        return ruch
Example #54
0
    def move(bot, game):
        x, y = bot.location
        RIGHT, UP, LEFT, DOWN = (1, 0), (0, -1), (-1, 0), (0, 1)
        prio = ()
        result = False

        if rg.locs_around(tuple(bot.location),
                          filter_out=('invalid', 'obstacle',
                                      'normal')):  #We are out of order
            return False

        if x <= 9 and y > 9:  #lower left quadrant; moving right and down priority
            if bot.hp >= CRITICAL_HP:
                prio = (DOWN, RIGHT, UP, LEFT)
            else:
                prio = (LEFT, UP, RIGHT, DOWN)
        elif x > 9 and y >= 9:  #lower right; right and up
            if bot.hp >= CRITICAL_HP:
                prio = (RIGHT, UP, LEFT, DOWN)
            else:
                prio = (DOWN, LEFT, UP, RIGHT)
        elif x > 9 and y <= 9:  #upper right; up and left
            if bot.hp >= CRITICAL_HP:
                prio = (UP, LEFT, DOWN, RIGHT)
            else:
                prio = (RIGHT, DOWN, LEFT, UP)
        elif x <= 9 and y <= 9:  #upper left; left and down
            if bot.hp >= CRITICAL_HP:
                prio = (LEFT, DOWN, RIGHT, UP)
            else:
                prio = (UP, RIGHT, DOWN, LEFT)
        else:
            prio = (UP, )

        for d in prio:
            dest = (x + d[0], y + d[1])
            occupied = False
            for loc, nbot in game.get('robots').items():
                if bot.hp >= CRITICAL_HP and nbot.hp < CRITICAL_HP and nbot.get(
                        "location") == dest:
                    continue
            if occupied:  #if it is occupied by an ally, check for a less prioritized move, but if not, try moving anyway
                result = ["move", dest]
                continue
            elif "spawn" in rg.loc_types(dest) or "invalid" in rg.loc_types(
                    dest):
                continue
            elif bot.hp < CRITICAL_HP:
                x2 = dest[0] + d[0]
                y2 = dest[1] + d[
                    1]  # Also check the tile after, so we go in the second row instead
                if "spawn" in rg.loc_types((x2, y2)):
                    continue
                else:
                    result = ["move", dest]
            else:
                result = ["move", dest]
                break
        return result
Example #55
0
 def find_random_safe_loc(loc, grid):
     arounds = filter(
         lambda x: not x in spawns and 0 == count_enemies(x) and not np.
         inf == grid[x],
         rg.locs_around(loc, filter_out=['invalid', 'obstacle']))
     if 0 == len(arounds):
         return None
     return choice(arounds)
Example #56
0
def surrounders(this_robot, game, loc):
    number_found = 0
    for loc2 in rg.locs_around(loc):
        if (loc2 in game.robots):
            bot2 = game.robots[loc2]
            if bot2.player_id != this_robot.player_id: number_found += 1
    #print "surrounders found ", loc, game
    return number_found
Example #57
0
def get_neighboring_enemies(robot, game):
    neighboring_enemies = []
    neighbors = rg.locs_around(robot.location)
    for loc, other in game['robots'].items():
        if loc in neighbors:
            if other.player_id != robot.player_id:
                neighboring_enemies.append(other.location)
    return neighboring_enemies
Example #58
0
 def guessShot():
     for potentialShot in rg.locs_around(self.location,
                                         filter_out=('invalid',
                                                     'obstacle')):
         allyCount = 0
         enemyCount = 0
         if potentialShot not in game['robots']:
             for enemy in rg.locs_around(potentialShot,
                                         filter_out=('invalid',
                                                     'obstacle')):
                 if enemy in game['robots']:
                     if game['robots'][
                             enemy].player_id != self.player_id:
                         enemyCount += 1
             if enemyCount > 0:
                 return ['attack', potentialShot]
     return ['attack', rg.toward(self.location, closestEnemy)]