Ejemplo n.º 1
0
    def doPostOffense(self):
        log.info("Post-Offense phase")
        if len(self.enemy_planets) == 0:
            return

        planets_to_send_to = copy(self.my_planets)
        neutral_candidate = self.closest_to_enemy_neutral_under_my_attack()
        if neutral_candidate is not None:
           planets_to_send_to = planets_to_send_to | neutral_candidate

        # cache closest and com enemy planet distances
        closest_enemy_planet_distance_map = {}
        com_enemy_planet_distance_map = {}
        for planet in planets_to_send_to:
            closest_enemy_planet_distance_map[planet] = self.closest_enemy_planet_distance(planet)
            com_enemy_planet_distance_map[planet] = self.enemy_com.distance(planet)

        my_nearest_to_enemy_planets = sorted(planets_to_send_to, key=lambda p : p.distance(self.enemy_com) +  p.id/1000000.0)

        for source_planet in self.my_planets:
            if self.ships_needed[source_planet] == 0 and self.ships_available_at_turn[source_planet][0] > 0:
                #log.info("Post-Offense for %s" % source_planet)
                for dest_planet in my_nearest_to_enemy_planets:
                    distance = source_planet.distance(dest_planet)
                    if distance > 0 and distance < com_enemy_planet_distance_map[source_planet]:
                        if com_enemy_planet_distance_map[dest_planet] < com_enemy_planet_distance_map[source_planet] and \
                          closest_enemy_planet_distance_map[dest_planet] <= closest_enemy_planet_distance_map[source_planet]:
                            self.send_fleet(source_planet, dest_planet, self.ships_available_at_turn[source_planet][0])
                            self.decrease_ships_available(source_planet, 0, self.ships_available_at_turn[source_planet][0])
                            break
Ejemplo n.º 2
0
    def doPostOffense(self):
        log.info("Post-Offense phase")
        if len(self.enemy_planets) == 0:
            return

        planets_to_send_to = copy(self.my_planets)
        neutral_candidate = self.closest_to_enemy_neutral_under_my_attack()
        if neutral_candidate is not None:
           planets_to_send_to = planets_to_send_to | neutral_candidate

        # cache closest and com enemy planet distances
        closest_enemy_planet_distance_map = {}
        com_enemy_planet_distance_map = {}
        for planet in planets_to_send_to:
            closest_enemy_planet_distance_map[planet] = self.closest_enemy_planet_distance(planet)
            com_enemy_planet_distance_map[planet] = self.enemy_com.distance(planet)

        my_nearest_to_enemy_planets = sorted(planets_to_send_to, key=lambda p : p.distance(self.enemy_com) +  p.id/1000000.0)

        for source_planet in self.my_planets:
            if self.ships_needed[source_planet] == 0 and self.ships_available_at_turn[source_planet][0] > 0:
                #log.info("Post-Offense for %s" % source_planet)
                for dest_planet in my_nearest_to_enemy_planets:
                    distance = source_planet.distance(dest_planet)
                    if distance > 0 and distance < com_enemy_planet_distance_map[source_planet]:
                        if com_enemy_planet_distance_map[dest_planet] < com_enemy_planet_distance_map[source_planet] and \
                          closest_enemy_planet_distance_map[dest_planet] <= closest_enemy_planet_distance_map[source_planet]:
                            source_planet.send_fleet(dest_planet, self.ships_available_at_turn[source_planet][0])
                            self.decrease_ships_available(source_planet, 0, self.ships_available_at_turn[source_planet][0])
                            break
Ejemplo n.º 3
0
    def doPostOffense2(self):
        log.info("Post-Offense phase")
        if len(self.enemy_planets) == 0:
            return

        planets_to_send_to = copy(self.my_planets)
        neutral_candidate = self.closest_to_enemy_neutral_under_my_attack()
        if neutral_candidate is not None:
            planets_to_send_to = planets_to_send_to | neutral_candidate

        for source_planet in self.my_planets:
            closest_enemy_planet = self.closest_enemy_planet(source_planet)
            #log.info("Eval Post-Offense for %s: closest enemy is %s" % (source_planet, closest_enemy_planet))
            min_distance_to_enemy = 1000000
            dest_planet = None
            for planet_to_send_to in sorted(
                    planets_to_send_to,
                    key=lambda p: p.id
                    if p.id != source_planet.id else 1000000):
                if source_planet.distance(planet_to_send_to) < source_planet.distance(closest_enemy_planet) \
                  and planet_to_send_to.distance(closest_enemy_planet) < min_distance_to_enemy:
                    min_distance_to_enemy = planet_to_send_to.distance(
                        closest_enemy_planet)
                    dest_planet = planet_to_send_to
            if dest_planet is not None and source_planet.id != dest_planet.id and self.ships_available_at_turn[
                    source_planet][0] > 0:
                ships_to_send = min(
                    self.ships_available_at_turn[source_planet][0],
                    source_planet.ship_count)
                self.send_fleet(source_planet, dest_planet, ships_to_send)
                self.decrease_ships_available(source_planet, 0, ships_to_send)
Ejemplo n.º 4
0
    def doPostOffense2(self):
        log.info("Post-Offense phase")
        if len(self.enemy_planets) == 0:
            return

        planets_to_send_to = copy(self.my_planets)
        neutral_candidate = self.closest_to_enemy_neutral_under_my_attack()
        if neutral_candidate is not None:
           planets_to_send_to = planets_to_send_to | neutral_candidate

        for source_planet in self.my_planets:
            closest_enemy_planet = self.closest_enemy_planet(source_planet)
            #log.info("Eval Post-Offense for %s: closest enemy is %s" % (source_planet, closest_enemy_planet))
            min_distance_to_enemy = 1000000
            dest_planet = None
            for planet_to_send_to in planets_to_send_to:
                if source_planet.distance(planet_to_send_to) < source_planet.distance(closest_enemy_planet) \
                  and planet_to_send_to.distance(closest_enemy_planet) < min_distance_to_enemy:
                    min_distance_to_enemy = planet_to_send_to.distance(closest_enemy_planet)
                    dest_planet = planet_to_send_to
            if dest_planet is not None and source_planet.id != dest_planet.id and self.ships_available_at_turn[source_planet][0] > 0:
                source_planet.send_fleet(dest_planet, self.ships_available_at_turn[source_planet][0])
                self.decrease_ships_available(source_planet, 0, self.ships_available_at_turn[source_planet][0])