Пример #1
0
 def act(self, game):
     active_team = {}
     active_enemy = {}
     enemy_distance = {}
     active_bots = {}
     for loc, bot in game.get('robots').items():
         if bot.player_id != self.player_id:
             active_enemy[loc] = bot                
             enemy_distance[loc] = 0
         else:
             active_team[loc] = bot
     for loc, bot in game.get('robots').items():
         active_bots[loc] = bot
     for loc in active_enemy:
         for myloc in active_team:
             enemy_distance[loc] = enemy_distance[loc] + rg.dist(loc, myloc)
     if self.hp <= 20:
         return flee(self, active_enemy, active_team, game)
     if 'spawn' in rg.loc_types(self.location):
         if game['turn'] %10 == 0: #spawn about to happen, gtfo
             return ['move', rg.toward(self.location, rg.CENTER_POINT)]
     for loc, bot in game['robots'].iteritems():
         if bot.player_id != self.player_id:
             if rg.dist(loc, self.location) <= 1:
                 print("ATTACK")
                 return ['attack', loc]
             else:                    
                 return['move', rg.toward(self.location, bot.location)]
Пример #2
0
    def act(self, game):
        # if health < 20, just move to the centre
        if self.hp < 20:
            if self.location == rg.CENTER_POINT:
                return ['guard']
            # if there are enemies around, attack them
            for loc, bot in self.enemy_list(game):
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]
            # move toward the center
            return self.next_move(rg.CENTER_POINT, game)

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

        #else, move towards weakest enemy
        target_bot = self.find_weakest_bot(self.friendly_list(game),game)
        destination = target_bot.location
        move = self.next_move(destination, game)

        if move is None:
            return ['guard']
        return ['move', move]
Пример #3
0
 def act(self, game):
     us, them = process_game(game, self.player_id)
     x = int(sum([x[0] for x in us]) / len(us))
     y = int(sum([y[1] for y in us]) / len(us))
     if self.location == (x, y):
         return ['guard']
     enemies_around = list()
     friends_around = list()
     for each in them:
         if rg.dist(self.location, each) == 1:
             enemies_around.append(each)
     for each in us:
         if rg.dist(self.location, each) == 1:
             friends_around.append(each)
     if len(friends_around) >= 3:
         return ['guard']
     distance_border = min([
         rg.wdist(place, self.location)
         for place in rg.settings.spawn_coords
     ])
     if len(friends_around) >= 2 and distance_border > 3:
         return ['guard']
     if len(enemies_around) >= 2:
         return ['suicide']
     if self.hp < 8 and enemies_around:
         return ['suicide']
     for each in them:
         if rg.dist(self.location, each) == 1:
             if test_location(each):
                 return ['attack', each]
     if test_location((x, y)):
         return ['move', rg.toward(self.location, (x, y))]
     return ['guard']
Пример #4
0
		def checkPos():
			r = 0
			searched = []
			print(shared['enemyList'])
			for pos in rmELocFromPlaces():
				if len(shared['enemyList']) > 0:
					for posEnemy in shared['enemyList']:
						for r_searched in range(1, R_MAX_SEARCH + 1):
							if rg.dist(pos, posEnemy) <= r_searched:
								if r_searched - 1 >= 0:
									searched.append({'loc': pos, 'r': r_searched - 1})
								break
				else:
					searched.append({'loc': pos, 'r': R_MAX_SEARCH})
					
			for pos in searched:
				if pos['r'] > r:
					r = pos['r']
							
			for pos in searched:
				if pos['r'] < r:
					searched = [x for x in searched if x['r'] >= r]
					
			savePosDist = rg.dist(self.location, searched[0]['loc'])
			savePos = searched[0]['loc']
			
			for pos in searched:
				if savePosDist > rg.dist(self.location, pos['loc']):
					savePosDist = rg.dist(self.location, pos['loc'])
					savePos = pos['loc']
			
			#print(savePos)
			shared['safeSpace'] = savePos
Пример #5
0
 def act(self, game):
     
     print
     print "Turn: " +str( game.turn) + "\tBot: " + str(self.robot_id)
     # find closest friend & enemy
     closestFriend = (1000, 1000)
     closestEnemy = (1000, 1000)
     for loc, bot in game.get('robots').items():
         if bot.player_id != self.player_id:
             if rg.wdist(loc, self.location) <= rg.wdist(closestEnemy, self.location):
                 closestEnemy = loc
         else:
             if rg.wdist(loc, self.location) <= rg.wdist(closestFriend, self.location) and self.robot_id != bot.robot_id:
                 closestFriend = loc
     
     for loc, bot in game['robots'].iteritems():
         # if there are enemies around, attack them
         if bot.player_id != self.player_id:
             if rg.dist(loc, self.location) <= 1:
                 return ['attack', loc]
         else:
             # if there are friends around, move to them
             if rg.dist(loc, self.location) > 2:
                 return ['move', rg.toward(self.location, closestFriend)]
                 
     # move towards enemy
     return ['move', rg.toward(self.location, closestEnemy)]
Пример #6
0
        def score_orientation(loc):
            self.orientation_score = 0

            #Terrain types
            self._loc_type = rg.loc_types(loc)
            if 'spawn' in self._loc_type:
                self.orientation_score += spawn
                if 'spawn' in rg.loc_types(base_bot):
                    self.orientation_score += spawn_move

            # Distance to center
            self.dist_to_center = round(rg.dist(loc, gravity_center))
            if self.dist_to_center <= inner_circle:
                self.dist_to_center = 0
            self.orientation_score += - self.dist_to_center

            #Distance to friends
            self.dist_to_closest_friend = 0
            for loc2 in friends:
                self._ref_dist = 16
                self.dist_to_closest_friend = 16
                self.dist_to_closest_friend = rg.dist(loc, loc2)
                if self.dist_to_closest_friend < self._ref_dist:
                    self._ref_dist = self.dist_to_closest_friend
            self.orientation_score += round(self.dist_to_closest_friend)
            return self.orientation_score
Пример #7
0
	def act(self, game):
		x,y = self.location
		bot = None
		active_team = {}
		active_enemy = {}
		enemy_distance  = {}
		for loc, bot in game.get('robots').items():
			if bot.get('player_id') != self.player_id:
				active_enemy[loc] = bot
				enemy_distance[loc] = 0
			else:
				active_team[loc] = bot
		for loc in active_enemy:
			for myloc in active_team:
				enemy_distance[loc] = enemy_distance[loc] + rg.dist(loc, myloc)
		prio_loc, attack_loc = self.findPriority(active_team, active_enemy,enemy_distance)
		distance_to_prio = rg.dist(self.location,prio_loc)
		distance_to_attack = BIG_DIST
		if attack_loc:
			distance_to_attack = rg.dist(self.location,attack_loc)
			if distance_to_attack<=1:
				return ['attack', attack_loc]
			else:
				return ['move', rg.toward(self.location, prio_loc)]
		else:
			if prio_loc == self.location:
				if self.hp < SELF_CRITICAL:
					return ['suicide']
				return ['guard']
			return ['move',rg.toward(self.location,prio_loc)]
		return ['guard']
Пример #8
0
        def score_orientation(loc):
            self.orientation_score = 0

            #Terrain types
            self._loc_type = rg.loc_types(loc)
            if 'spawn' in self._loc_type:
                self.orientation_score += spawn
                if 'spawn' in rg.loc_types(base_bot):
                    self.orientation_score += spawn_move

            # Distance to center
            self.dist_to_center = round(rg.dist(loc, gravity_center))
            if self.dist_to_center <= inner_circle:
                self.dist_to_center = 0
            self.orientation_score += -self.dist_to_center

            #Distance to friends
            self.dist_to_closest_friend = 0
            for loc2 in friends:
                self._ref_dist = 16
                self.dist_to_closest_friend = 16
                self.dist_to_closest_friend = rg.dist(loc, loc2)
                if self.dist_to_closest_friend < self._ref_dist:
                    self._ref_dist = self.dist_to_closest_friend
            self.orientation_score += round(self.dist_to_closest_friend)
            return self.orientation_score
Пример #9
0
    def act(self, game):
        # Attack nearby robots. Suicide if we are low on health.
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    if self.hp <= 11 and bot.hp <= 15:
                        return ['suicide']
                    else:
                        return ['attack', loc]

        # Find the nearest enemy bot and move towards it if we can. Otherwise head to the center.
        distanceToEnemy = 50
        enemyLocation = rg.CENTER_POINT

        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                distance = rg.dist(loc, self.location)
                if distanceToEnemy > distance:
                    distanceToEnemy = distance
                    enemyLocation = loc

        moveToPoint = rg.toward(self.location, loc)

        if moveToPoint == self.location:
            return ['guard']

        if 'normal' in rg.loc_types(moveToPoint):
            return ['move', moveToPoint]
        else:
            return ['guard']
Пример #10
0
    def act(self, game):

        # check if being attacked
        if self.last_turns_hp < self.hp:
            self.bait = True
        last_turns_hp = self.hp

        # guard if attacked
        if self.bait:
            return ['guard']

        closest_bot_loc = None
        closest_bot_distance = 50000
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    if self.hp < 11:
                        return ['suicide']
                    else:
                        return ['attack', loc]
                if rg.dist(loc, self.location) < closest_bot_distance:
                    closest_bot_distance = rg.dist(loc, self.location)
                    closest_bot_loc = loc

        # move towards an enemy
        if closest_bot_loc:
            move_loc = rg.toward(self.location, closest_bot_loc)
            if move_loc not in game['robots']:
                return ['move', move_loc]
        return ['guard']
Пример #11
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
Пример #12
0
    def act(self, game):
        # if health < 40, just move to the centre
        if self.hp < 40:
            if self.location == rg.CENTER_POINT:
                return ['guard']
            # 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:
                        return ['attack', loc]
            # move toward the center
            return ['move', rg.toward(self.location, rg.CENTER_POINT)]

        # 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:
                    return ['attack', loc]

        #else, move towards weakest enemy
        enemy = self.find_weakest_enemy(game)

        destination = enemy.location
        move = self.next_move(destination, game)
        if move is None:
            return ['guard']
        return ['move', move]
Пример #13
0
    def act(self, game):
        enemies = []
        friends = []
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                enemies.append(bot)
            else:
                friends.append(bot)

        enemies_distances = dict()
        for enemy in enemies:
            enemies_distances[enemy.location] = [0, enemy]
            for friend in friends:
                enemies_distances[enemy.location][0] += rg.dist(friend.location, enemy.location)

        closest_enemies = sorted(enemies_distances.items(), key=lambda x: x[1][0])
        closest_enemies = closest_enemies[:len(closest_enemies)/2]

        # 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:
                    return ['attack', loc]

        loc, (distance, closest_enemy) = closest_enemies[0]
        closest_enemy = closest_enemies[0][1][1]
        for loc, (distance, enemy) in closest_enemies:
            if rg.dist(enemy.location, self.location) < rg.dist(closest_enemy.location, self.location):
                closest_enemy = enemy

        return ['move', rg.toward(self.location, closest_enemy.location)]
Пример #14
0
    def act(self, game):
        if self.hp < 14:
            return ['suicide']

        # Calculate nearby bots
        nearby_bots = 0
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 2:
                    nearby_bots += 1
                    enemy_loc = loc

        # Attack or suicide if bots nearby
        if nearby_bots == 1:
            if rg.dist(enemy_loc, self.location) == 1:
                return ['attack', enemy_loc]
            else:
                return ['attack', rg.toward(self.location, enemy_loc)]
        elif nearby_bots > 2:
            return ['suicide']

        # If already at center, guard the center
        if self.location == rg.CENTER_POINT:
            return ['guard']

        # Move to center
        next_move_to_center = rg.toward(self.location, rg.CENTER_POINT)

        #import pdb; pdb.set_trace()
        if next_move_to_center in game['robots']:
            return ['guard']

        return ['move', next_move_to_center]
Пример #15
0
    def act(self, game):

        # if we're on one of the corners, guard
        if self.location in self.corners:
            return ['guard']

        # 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:
                    return ['attack', loc]
                #elif rg.dist(loc, self.location) <= 2:
                #    new_loc = rg.toward(self.location,
                #                        loc)
                #    return ['move', new_loc]

        distances = {}
        for corner in self.corners:
            distances[corner] = rg.dist(self.location, corner)

        new_loc = rg.toward(self.location, min(distances, key=distances.get))

        if 'obstacle' in rg.loc_types(new_loc):
            return ['guard']
        else:
            return ['move', new_loc]
Пример #16
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
Пример #17
0
 def closestSpawnpoint(self, loc, radius=rg.settings.board_size):
     spawn = None
     initial = radius
     for s in rg.settings.spawn_coords:
         if rg.dist(loc, s) <= initial:
             spawn = s
             initial = rg.dist(loc, s)
     return spawn
Пример #18
0
    def act(self, game):
        if "spawn" in rg.loc_types(self.location):
            s = sanitize(['move', rg.toward(self.location, rg.CENTER_POINT)])
            return s

        adjacent_enemies = []
        for loc, bot in game.get('robots').items():
            if bot.get('player_id') != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    allies = 0
                    #Find out how many allies are around this enemy
                    for nloc, nbot in game.get('robots').items():
                        if bot.get("player_id") == self.player_id and rg.dist(loc, nloc) <=1:
                            allies = allies + 1
                    adjacent_enemies.append([loc, bot, allies])
            else:
                if "spawn" in rg.loc_types(bot.get("location")): #The friendly wants to get out of spawn, make way for it
                    r = Robot.move(self, game)
                    if r and rg.toward(bot.get("location"), rg.CENTER_POINT) == r[1]:
                            return sanitize(['move', rg.toward(self.location, rg.CENTER_POINT)])
        if adjacent_enemies and self.hp >= CRITICAL_HP:
            if len(adjacent_enemies) * ATTACK_DAMAGE > self.hp: # They can kill me! lets flee!
                return sanitize(self.flee(game))
            adjacent_enemies.sort(key= lambda x: (x[2], x[1].get("hp")))
            return sanitize(['attack', adjacent_enemies[0][0]])
        elif adjacent_enemies and self.hp < CRITICAL_HP:
            return sanitize(self.flee(game))
        else:
            r = Robot.move(self, game)

            if not r:
                return ["guard"]
            
            #Check if allied damaged bots will move to our destination, and if so, let them
            move = True
            for loc, bot in game.get('robots').items():
                if bot.get("player_id") == self.player_id and not bot.location == self.location:
                    if rg.dist(loc, r[1]) <= 1:
                        if Robot.get_destination(bot, game) == r[1]: #our destination matches, let them come
                            if bot.get("hp") < CRITICAL_HP:
                                return ["guard"]
                            else: # Figure out who should be given highest movement priority (based on which one is furthest from middle, or who has lowest hp in tiebreaker)
                                prio = rg.dist(self.location, rg.CENTER_POINT)
                                prio_o = rg.dist(bot.location, rg.CENTER_POINT)

                                if prio == prio_o: #Tie
                                    if self.hp >= bot.hp:
                                        move = True
                                    else:
                                        move = False
                                elif prio > prio_o:
                                    move = True
                                else:
                                    move = False
            if not move:
                return ["guard"]
            else:
                return sanitize(r) or ["guard"]
Пример #19
0
 def act(self, game):
     available = rg.locs_around(self.location, filter_out = ('invalid', 'obstacle'))
     for loc, bot in game.robots.iteritems():
         if bot.player_id != self.player:
             if rg.dist(loc, self.location) == 1:
                 return ['attack', loc]
             elif rg.dist(loc, self.location) <= 3:
                 return ['move', rg.toward(self.location, loc)]
             else:
                 return ['move', rg.toward(self.location, rg.CENTER_POINT)]
Пример #20
0
def run_if_scared_and_safe(this_robot, game, illegals): 
    if not scared(this_robot, game):
        return 'no_action'
    best_distance = 1000
    move = 'no_action'
    for loc in rg.locs_around(this_robot.location, filter_out=('obstacle', 'invalid', 'spawn')):
        if ((not loc in illegals) and safe(this_robot, loc, game) == 1):
            if rg.dist(loc, rg.CENTER_POINT) < best_distance:
                best_distance = rg.dist(loc, rg.CENTER_POINT)
                move = ['move', loc]
    return move
Пример #21
0
def run_if_scared_and_safe(this_robot, game, illegals):
    if not scared(this_robot, game):
        return 'no_action'
    best_distance = 1000
    move = 'no_action'
    for loc in rg.locs_around(this_robot.location,
                              filter_out=('obstacle', 'invalid', 'spawn')):
        if ((not loc in illegals) and safe(this_robot, loc, game) == 1):
            if rg.dist(loc, rg.CENTER_POINT) < best_distance:
                best_distance = rg.dist(loc, rg.CENTER_POINT)
                move = ['move', loc]
    return move
Пример #22
0
        def checkPos():
            r = 0
            searched = []
            newReqiured = False
            #print(shared['enemyList'])
            for pos in rmEnemyLoc():
                #print(1)
                if len(shared['enemyList']) > 0:
                    #print(2)
                    for posEnemy in shared['enemyList']:
                        #print(3)
                        for r_searched in range(1, R_MAX_SEARCH + 1):
                            #print(4)
                            if rg.dist(pos, posEnemy) <= r_searched:
                                #print(5)
                                if r_searched - 1 >= 0:
                                    searched.append({
                                        'loc': pos,
                                        'r': r_searched - 1
                                    })
                                    #print(6)
                                break
                else:
                    searched.append({'loc': pos, 'r': R_MAX_SEARCH})

            for pos in searched:
                if pos['r'] > r:
                    r = pos['r']

            for pos in searched:
                if pos['r'] < r:
                    searched = [x for x in searched if x['r'] >= r]

            safePosDist = rg.dist(self.location, searched[0]['loc'])
            safePos = searched[0]['loc']

            if len(shared['safeSpace']):
                for pos in searched:
                    if shared['safeSpace'] == pos['loc']:
                        print('#' + str(shared['safeSpace']))
                        return 0

            for pos in searched:
                if safePosDist > rg.dist(self.location, pos['loc']):
                    safePosDist = rg.dist(self.location, pos['loc'])
                    safePos = pos['loc']

            #print(safePos)
            print(safePos)
            shared['safeSpace'] = safePos
Пример #23
0
 def giveOrder(self, my_bot):
     # Surround the enemy, if the bot is already next to the enemy then decide to attack or guard or suicide if the bot is surrounded.
     shortest = None
     
     #if my_bot.hp <= rg.settings.attack_range[1]:
     #    return self.panic(my_bot)
     
     for enemy_loc, enemy_bot in self.enemy_bots.iteritems():
         dist = rg.dist(my_bot.location, enemy_loc)
             
         # Found enemy adjacent to bot, attack it or guard
         if dist <= 1:
             return self.guardOrAttack(my_bot, enemy_bot)
         # Found enemy two spaces away, attack open spot in between in case it moves there.
         #elif dist <= 2 and random.randint(0,1) == 1:
         #    return self.preemptiveAttack(my_bot, enemy_bot)
         # Find the enemy closest to bot, ignoring any enemies that are already surrounded
         if len(self.open_locs_around(enemy_loc)) > 0:
             if shortest == None or dist < shortest[0]:
                 shortest = (dist, enemy_loc)
                 
     # Bot is not directly next to enemy, try to move to a spot adjacent to the closest enemy. 
     if shortest != None:     
         return self.moveTowards(my_bot, shortest[1])
     # All enemy bots are surrounded, just default this bot to move towards center or guard if already at center.
     else:
         return self.moveTowards(my_bot, rg.CENTER_POINT)
Пример #24
0
      def act(self, game):

                  minDist = 1000000
                  minDistLoc = self.location
                  for loc, bot in game['robots'].iteritems():                                
                                if bot.player_id != self.player_id:
                                                  if rg.dist(loc, self.location) <= 1:
                                                                        return ['attack', loc]


                                elif rg.dist(loc,self.location) < minDist:
                                        minDist = rg.dist(loc,self.location)
                                        minDistLoc = loc

                  
                  return ['move',rg.toward(self.location,loc)]
Пример #25
0
    def act(self, game):
        ennemies_around = []
        toward_center_location = rg.toward(self.location, rg.CENTER_POINT)
        
        for location, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(location, self.location) <= 1:
                    ennemies_around.append(location)

            if location == toward_center_location:
                if bot.player_id == self.player_id:
                    return ['guard']
                    

        if len(ennemies_around) > 2:
            return ['suicide']
        if len(ennemies_around) > 0:
            return ['attack', ennemies_around[0]]

        for location, bot in game.robots.iteritems():
            if bot.player_id == self.player_id:
                if self.give_way(location, toward_center_location):
                    print location, toward_center_location, self.location
                    return ['guard']

        return ['move', rg.toward(self.location, rg.CENTER_POINT)]
Пример #26
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]
Пример #27
0
    def act(self, game):
        assert len(set(r.player_id for r in game.robots.values())) > 1
        enemies = self.enemies_around_me(game)
        #enemyhp = sum(enemy.hp for enemy in enemies)

        # if we're likely to die anyway, kill ourselves
        if self.hp < 9 * len(enemies):
            return ["suicide"]

        # attack the first weak-looking enemy we can see
        for enemy in enemies:
            if enemy.hp < 10:
                return ["attack", enemy.location]


        # 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:
                    return ['attack', loc]

        # if we're at or near the destination, stay put
        if self.location == DESTINATION:
            return ['guard']
        # if we're near the destination and there's a friend there, stay put
        if DESTINATION in game.robots:
            robot_at_destination = game.robots[DESTINATION]
            if robot_at_destination.player_id == self.player_id:
                if rg.wdist(self.location, DESTINATION) == 1:
                    return ['guard']

        # move towarde center
        return self.move(game)#['move', ideal_destination(self.location)]
Пример #28
0
 def nearestMember(self, location):
     selected = {}
     dist = 100
     for bot in self.bots:
         if rg.dist(bot.location, location) < dist:
             selected = bot
     return selected
Пример #29
0
def strong_hunt_the_weak(this_robot, game, illegals):
    if(this_robot.hp < 30): return 'no_action'
    weakest_enemy = 20
    best_move = 'no_action'
    for bot in one_robots:
        if bot.player_id != this_robot.player_id:
            if bot.hp < weakest_enemy:
                weakest_enemy = bot.hp
                if bot.hp <= 5 and (not bot.location in illegals) and (not surrounders(this_robot, game, bot.location) > 1):
                    best_move = ['move', bot.location]
                    weakest_enemy = bot.hp
                elif not this_robot.location in illegals:
                    best_move = ['attack', bot.location]
                    weakest_enemy = bot.hp
    for bot in two_robots:
        if bot.player_id != this_robot.player_id:
            if bot.hp < weakest_enemy:
                targetx = towardsx_if_not_spawn(this_robot.location, bot.location)
                targety = towardsy_if_not_spawn(this_robot.location, bot.location)
                if not (targetx == 'no_move'):
                    if not (targetx in illegals or surrounders(this_robot, game, targetx) > 1):
                        best_move = ['move', targetx]
                        weakest_enemy = bot.hp
                if not (targety == 'no_move'):
                    if not (targety in illegals or surrounders(this_robot, game, targety) > 1):
                        if targetx == 'no_move' or rg.dist(targetx, rg.CENTER_POINT) > rg.dist(targety, rg.CENTER_POINT):
                        	best_move = ['move', targety]
                        	weakest_enemy = bot.hp
    return best_move
Пример #30
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]
Пример #31
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']
	def __cautious_stance(self, towards, recursive = False):
		"""Attacks neighbours, then tries to help friends, otherwise attacks towards.
		
		Preconditions:
			no safe location exists
			is not endangered"""

		#print "cautious_stance"

		# if we're already there, try to move to attack nearby enemies
		# not random for now, maybe fix later
		if not recursive:
			if self.robot.location == towards:
				for loc, bot in self.arena_data.game.robots.iteritems():
					if bot.player_id != self.robot.player_id:
						if rg.dist(loc, self.robot.location) <= 3:
							return self.__aggressive_stance(rg.toward(self.robot.location, loc), recursive=True)

			# help adjacent allies as second priority
			for loc in self.local_data.unobstructed_locs:
				if self.__can_flank_enemy_safely(loc):
					if not recursive:
						if not self.__friendly_running_into_me(loc):
							return ['move', loc]
					else:
						return ['move', loc]

			# attack immediate neighbours first
			possible_attack = self.__attack_if_beside(self.robot)
			if possible_attack:
				return possible_attack

		# attack possible enemy move locations
		return ['attack', towards]
Пример #33
0
    def act(self, game):
        num_enemies = self.num_enemies(game)
        if num_enemies * 9 > self.hp:
            return ['suicide']

        min_distance = float("inf")
        move_to = self.get_center(game)
        for location, bot in game.get('robots').items():
            if bot.get('player_id') != self.player_id:
                if rg.dist(location, self.location) <= 1:
                    return ['attack', location]
            if bot.get('player_id') == self.player_id:
                if rg.wdist(location, self.location) < min_distance:
                    min_distance = rg.wdist(location, self.location)
                    move_to = location
        if min_distance < 2:
            move_to = self.get_center(game)
        
        if self.location == self.get_center(game):
            return ['guard']
        
        if self.num_frieds(game) > 1:
            return ['guard']
        
        return ['move', rg.toward(self.location, move_to)]
Пример #34
0
    def act(self, game):
        # 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:
        #            return ['attack', loc]
					print loc
					#print ("PlayerID: ", self.player_id)
					print ("RobotID: ", self.robot_id)

            
        # get enemies
        enemies = []
        for loc in around(self.location):
            if isenemy(loc):
                enemies.append(loc)

        moveable = []
        moveable_safe = []
        for loc in around(self.location):
            if isempty(loc):
                moveable.append(loc)
            if isempty(loc) and not isspawn(loc):
                moveable_safe.append(loc)
                

        # if we're in the center, stay put
        if self.location == rg.CENTER_POINT:
            return ['guard']
        
	def isenemy(l):
        if robots.get(l) != None:
            if robots[l]['player_id'] != self.player_id:
                return True
        return False           
Пример #35
0
    def giveOrder(self, my_bot):
        # Surround the enemy, if the bot is already next to the enemy then decide to attack or guard or suicide if the bot is surrounded.
        shortest = None

        #if my_bot.hp <= rg.settings.attack_range[1]:
        #    return self.panic(my_bot)

        for enemy_loc, enemy_bot in self.enemy_bots.iteritems():
            dist = rg.dist(my_bot.location, enemy_loc)

            # Found enemy adjacent to bot, attack it or guard
            if dist <= 1:
                return self.guardOrAttack(my_bot, enemy_bot)
            # Found enemy two spaces away, attack open spot in between in case it moves there.
            #elif dist <= 2 and random.randint(0,1) == 1:
            #    return self.preemptiveAttack(my_bot, enemy_bot)
            # Find the enemy closest to bot, ignoring any enemies that are already surrounded
            if len(self.open_locs_around(enemy_loc)) > 0:
                if shortest == None or dist < shortest[0]:
                    shortest = (dist, enemy_loc)

        # Bot is not directly next to enemy, try to move to a spot adjacent to the closest enemy.
        if shortest != None:
            return self.moveTowards(my_bot, shortest[1])
        # All enemy bots are surrounded, just default this bot to move towards center or guard if already at center.
        else:
            return self.moveTowards(my_bot, rg.CENTER_POINT)
Пример #36
0
    def act(self, game):
        num_enemies = self.num_enemies(game)
        if num_enemies * 9 > self.hp:
            return ['suicide']

        min_distance = float("inf")
        move_to = rg.CENTER_POINT
        for location, bot in game.get('robots').items():
            if bot.get('player_id') != self.player_id:
                if rg.dist(location, self.location) <= 1:
                    return ['attack', location]
            if bot.get('player_id') == self.player_id:
                if rg.wdist(location, self.location) < min_distance:
                    min_distance = rg.wdist(location, self.location)
                    move_to = location
        if min_distance < 2:
            move_to = rg.CENTER_POINT
            
        if self.location == rg.CENTER_POINT:
            return ['guard']
        
        if self.num_frieds(game) > 1:
            return ['guard']
        
        return ['move', rg.toward(self.location, move_to)]
Пример #37
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']
Пример #38
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']
Пример #39
0
 def d(self,x,y):
     s = rg.dist(x,y)
     if self.gridscore[x]<0:
         s += -enemy_fact*self.gridscore[x]/2.
     if self.gridscore[y]<0:
         s += -enemy_fact*self.gridscore[y]/2.
     return s
Пример #40
0
    def act(self, game):
        
        myId = self.robot_id
        myAge = 0

        if myId in self.age:
            self.age[myId] += 1
            myAge = self.age[myId]
        else:
            self.age[myId] = 0
       
        # get off the spawn point fast
        if myAge <= 3:
            return ['move', rg.toward(self.location, rg.CENTER_POINT)]
        
        # 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:
                    return ['attack', loc]

                # if we're in the center, stay put
        if self.location == rg.CENTER_POINT:
            return ['guard']

        # move toward the center slowly
        if game.turn % 2:
            return ['move', rg.toward(self.location, rg.CENTER_POINT)]
        
        return['guard']
Пример #41
0
    def testact(self, game, meta=2):
        # self.__init__() #Calling __init__ because of LIES
        target = rg.CENTER_POINT

        if self.location == target:
            return self.guard()

        for loc, bot in game.get('robots').items():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return self.attack(loc)

        t0 = time()
        path = astar_find_path(self.location, target)
        t = time()
        print("A Star Pathfinding took "+str((t-t0)*1000)+" milliseconds. "+str(len(path))+" steps.")

        next_step = path[1]
        
        # t0 = time()
        # path = self.nice_find_path(self.location, target, game)
        # t = time()
        # print("Best-First Pathfinding took "+str((t-t0)*1000)+" milliseconds. "+str(len(path))+" steps.")

        if len(path) > 1:

            print(next_step)
            print("#############      awesome, we got a path      ###########")
            return self.move(next_step)

        print("CRAP: No path found from "+str(self.location))
        return self.guard()
Пример #42
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)]
Пример #43
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


        # Create a list of distances to the enemy bots and their
        # locations.
        enemy_dist_and_locs = [(rg.dist(loc, self.location), loc)
                                for loc, bot in game.robots.iteritems() if
                                bot.player_id != self.player_id ]

        # Now sort by distance.
        enemy_dist_and_locs = sorted(enemy_dist_and_locs)

        closest_dist, closest_loc = enemy_dist_and_locs[0]

        if closest_dist <= 1 :
            self.new_locs.append(self.location)
            return ['attack', closest_loc]

        move_towards = rg.toward(self.location, closest_loc)
        moves = rg.locs_around(self.location, filter_out=('invalid', 'obstacle'))
        moves = [loc for loc in moves if loc not in self.new_locs]

        # Move is allowed so make it.
        if move_towards in moves:
            self.new_locs.append(move_towards)
            return ['move', move_towards]

        random.seed()
        # Otherwise move around pick a direction that can randomly
        # move to and move there.
        if len(moves) > 0:
            dists_and_moves = [(rg.dist(loc, closest_loc), loc) for loc in moves]
            dists_and_moves = sorted(dists_and_moves)
            choice = dists_and_moves[0][1]

            self.new_locs.append(choice)
            return ['move', choice]


        self.new_locs.append(self.location)
        return ['guard']
Пример #44
0
 def find_attack_loc(bot):
     weakest_hp = 100
     attack_loc = None
     for loc, enemy in self.gamestate.get('enemies').items():
         if rg.dist(loc, bot.location) <= 1:
             if attack_loc is None or weakest_hp > enemy.get('hp'):
                 attack_loc = loc
     return attack_loc
Пример #45
0
 def flee_loc_sort(self, loc):
     ## how many neighbours? 
     num_neighbours = len(self.find_enemy_neighbours(loc))
     
     ## how far from flee point?
     dist_to_flee = rg.dist(loc, self.get_flee_point())
     
     return (num_neighbours, dist_to_flee)
Пример #46
0
    def act(self, game):
        for loc, bot in game.robots.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]

        newLoc = randomLocation(self.location)
        return ['move', rg.toward(newLoc)]
Пример #47
0
 def find_attack_loc(bot):
     weakest_hp = 100
     attack_loc = None
     for loc, enemy in self.gamestate.get('enemies').items():
         if rg.dist(loc, bot.location) <= 1:
             if attack_loc is None or weakest_hp > enemy.get('hp'):
                 attack_loc = loc
     return attack_loc
Пример #48
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.iteritems():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    return ['attack', loc]
            if bot.player_id == self.player_id:
                if random.randint(0, 10) == 1:
                    if rg.dist(loc, self.location) <= 1:
                        return ['suicide', loc]

        # move toward the center
        return ['move', rg.toward(self.location, rg.CENTER_POINT)]
Пример #49
0
    def get_surrounding_enemy_locations(self, game):
        nearbys = []
        for loc, bot in game.robots.items():
            if bot.player_id != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    nearbys.append(loc)

        return nearbys
Пример #50
0
		def genPlacesToCheck():
			listToCheck = []
			for x in range(MIN['x'], MAX['x'] + 1):
				for y in range(MIN['y'], MAX['y'] + 1):
					if rg.dist((x, y), rg.CENTER_POINT) <= R_MAX_FROM_CENTER and ((x, y) not in shared['enemyList']) and rg.locs_around((x, y), filter_out = ('invalid', 'obstacle', 'spawn')):
						listToCheck.append((x, y))
									
			shared['genPlaces'] = listToCheck
Пример #51
0
    def flee_loc_sort(self, loc):
        ## how many neighbours?
        num_neighbours = len(self.find_enemy_neighbours(loc))

        ## how far from flee point?
        dist_to_flee = rg.dist(loc, self.get_flee_point())

        return (num_neighbours, dist_to_flee)
Пример #52
0
 def act(self, game):
     # Goal: Leave the spawn point and/or attack any adjacent enemy.
     
     # avoid bots moving into each other
     global move_intents
     # print "intents", move_intents
     
     global current_turn
     if current_turn is None or current_turn != int(game.get('turn')):
         move_intents = set()
         current_turn = int(game.get('turn'))
     
     # print "bot at", self.location
     
     spawn_move = True if 'spawn' in rg.loc_types(self.location) else False
     
     # if there are enemies around, attack them
     for loc, bot in game.get('robots').items():
         if bot.player_id != self.player_id:
             if rg.dist(loc, self.location) <= 1:
                 # print "attack", loc
                 return ['attack', loc]
         else:
             if 'spawn' in rg.loc_types(loc) and rg.dist(loc, self.location) <= 2:
                 spawn_move = True
     
     if spawn_move:
         # get possible move locations
         move_locs = set(rg.locs_around(self.location, filter_out=('invalid', 'obstacle')))
         move_locs -= move_intents
         
         for loc, bot in game.get('robots').items():
             if loc in move_locs:
                 # print "removing", loc, "from", move_locs
                 move_locs.remove(loc)
         
         move = rg.toward(self.location, rg.CENTER_POINT)
         # print "default", move, "out of", move_locs
         if move not in move_locs and len(move_locs) > 0:
             move = random.choice(list(move_locs))
         # print "move", move
         move_intents.add(move)
         return ['move', move]
         
     return ['guard']
Пример #53
0
 def attack_them(self, game):
     # if there are enemies around, attack them
     for loc, bot in game.get('robots').items():
         if bot.player_id != self.player_id:
             if rg.dist(loc, self.location) <= 1:
                 if self.hp < 7:
                     return ['suicide']
                 return ['attack', loc]
     return None
Пример #54
0
 def act(self, game):
     ilu_wrogow = 0
     for poz, robot in game.robots.iteritems():
         if robot.player_id != self.player_id:
             if rg.dist(poz, self.location) <= 1:
                 ilu_wrogow += 1
                 
     for poz, robot in game.robots.iteritems():
         if robot.player_id != self.player_id:
             if rg.dist(poz, self.location) <= 1:
                 if ilu_wrogow == 1 and self.hp > 10:
                     return['attack', poz]
                 else:
                     return['suicide']
     
     if self.location != rg.CENTER_POINT:
         return['move', rg.toward(self.location, rg.CENTER_POINT)]
     
     return['guard']
Пример #55
0
def nearest_loc(my_loc, locs):
    min_distance = 999
    nearest = None

    for loc in locs:
        distance = rg.dist(my_loc, loc)
        if distance < min_distance:
            min_distance = distance
            nearest = loc
    return nearest
Пример #56
0
    def move_score(self, game, loc):

        # don't move into spawn points
        if "spawn" in rg.loc_types(loc):
            return -10000 - rg.dist(loc, rg.CENTER_POINT)

        score = 0
        for rloc, r in game.robots.iteritems():
            d = rg.wdist(rloc, loc)
            if rloc == loc:

                # try not to collide with anyone
                score -= 100

            elif r.hp > self.hp and r.player_id != self.player_id:

                # stronger enemy adj to square, better not to move here
                if d == 1:
                    score -= 10

                # stronger enemy near square, better not to move here
                elif d == 2:
                    score -= 1

            elif r.player_id != self.player_id:

                # possible attack from weaker enemy
                if d == 1:
                    score -= 2

                # chase weaker enemy
                # else:
                # 	score += 2. / d

            elif r.player_id == self.player_id:

                # possible collision with teammate
                if d == 1:
                    score -= 1

        # move towards centre
        score -= rg.dist(loc, rg.CENTER_POINT) / 10.
        return score
Пример #57
0
    def moveTowards(self, my_bot, loc):
        if my_bot.location == loc:
            return self.guard(my_bot)

        locs = self.getNearbyOpenLocations(my_bot.location)
        # if bot has nowhere to move then just guard
        if len(locs) == 0:
            return self.guard(my_bot)

        locs = sorted(locs, key=lambda x: rg.dist(x, loc))
        return self.move(my_bot, locs[0])
Пример #58
0
    def act(self, game):
        dystans = rg.dist(self.location, rg.CENTER_POINT)

        #print dystans

        if dystans >= 7:
            return ['move', rg.toward(self.location, rg.CENTER_POINT)]

        # idź do środka planszy, ruch domyślny
        #return ['move', rg.toward(self.location, rg.CENTER_POINT)]
        return ['guard']