def get_best_planets_to_attack(self, count=1, turns=30, prod_turns=100): planet_score = {} #log.info("Score eval for %s planets" % len(self.universe.not_my_planets)) for planet_to_attack in self.universe.not_my_planets: log.info("Score eval for %s" % planet_to_attack) planet_score[planet_to_attack] = 0 planet_to_attack_future = planet_to_attack.in_future(turns) if planet_to_attack_future.owner == player.ME: continue my_nearest_planets = sorted( self.universe.my_planets, key=lambda p: p.distance(planet_to_attack)) for source in my_nearest_planets: log.info("Score eval source %s" % source) distance = source.distance(planet_to_attack) if self.ships_available[source] <= 0 or distance >= turns: continue if planet_to_attack.owner == player.NOBODY and \ distance > (self.closest_enemy_planet_distance(planet_to_attack) * ATTACK_PROXIMITY_RATIO): continue fleet_to_send = Fleet(self.universe, 12345, 1, self.ships_available[source], source.id, planet_to_attack.id, distance, distance) planet_to_attack_future = planet_to_attack.in_future( turns, fleet_to_send) if planet_to_attack_future.owner != player.ME: continue for ships_to_send in range(1, self.ships_available[source] + 1, 10): fleet_to_send = Fleet(self.universe, 12345, 1, ships_to_send, source.id, planet_to_attack.id, distance, distance) planet_to_attack_future = planet_to_attack.in_future( turns, fleet_to_send) if planet_to_attack_future.owner == player.ME: planet_score[ planet_to_attack] = planet_to_attack_future.ship_count - ships_to_send + prod_turns * planet_to_attack.growth_rate break if planet_score[planet_to_attack] > 0: break sorted_planets = sorted(self.universe.not_my_planets, key=lambda p: planet_score[p], reverse=True) result = sorted_planets[:count] if count < len( sorted_planets) else sorted_planets filtered_result = [] for p in result: if planet_score[p] > 0: filtered_result.append(p) for p in filtered_result: if planet_score[p] > 0: log.info("Score for %s is %s" % (p, planet_score[p])) log.info("Score eval done: %s planets" % len(result)) return filtered_result
def get_best_planets_to_attack(self, ships_available, count=1, turns=30): planet_score = {} #log.info("Score eval for %s planets" % len(self.universe.not_my_planets)) for planet_to_attack in self.universe.not_my_planets: log.info("Score eval for %s" % planet_to_attack) planet_score[planet_to_attack] = 0 planet_to_attack_future = planet_to_attack.in_future(turns) if planet_to_attack_future.owner == player.ME: continue my_nearest_planets = sorted( self.universe.my_planets, key=lambda p: p.distance(planet_to_attack)) for source in my_nearest_planets: log.info("Score eval source %s" % source) distance = source.distance(planet_to_attack) if ships_available[source] <= 0 or distance >= turns: continue fleet_to_send = Fleet(self.universe, 12345, 1, ships_available[source], source.id, planet_to_attack.id, distance, distance) planet_to_attack_future = planet_to_attack.in_future( turns, fleet_to_send) if planet_to_attack_future.owner != player.ME: break for ships_to_send in range(1, ships_available[source] + 1, 10): fleet_to_send = Fleet(self.universe, 12345, 1, ships_to_send, source.id, planet_to_attack.id, distance, distance) planet_to_attack_future = planet_to_attack.in_future( turns, fleet_to_send) if planet_to_attack_future.owner == player.ME: planet_score[planet_to_attack] = max( planet_score[planet_to_attack], planet_to_attack_future.ship_count - ships_to_send) break if planet_score[planet_to_attack] > 0: break sorted_planets = sorted(self.universe.not_my_planets, key=lambda p: planet_score[p], reverse=True) result = sorted_planets[:count] if count < len( sorted_planets) else sorted_planets for p in result: if planet_score[p] > 0: log.info("Score for %s is %s" % (p, planet_score[p])) log.info("Score eval done: %s planets" % len(result)) return result
def get_scheduled_fleets_from(self, planet): result = [] for moves in self.scheduled_moves_at_turn.values(): for move in moves: if move.source == planet: turns_remaining = move.turn - self.universe.game.turn_count fleet = Fleet(self.universe,random.randint(1,1000000),1, move.ship_count, move.source.id, move.target.id, turns_remaining, turns_remaining) result.append(fleet) return result
def get_scheduled_fleets_to(self, planet): result = [] for moves in self.scheduled_moves_at_turn.values(): for move in moves: if move.target == planet: distance = move.source.distance(move.target) turns_remaining = distance + (move.turn - self.universe.game.turn_count) fleet = Fleet(self.universe,12345,1, move.ship_count, move.source.id, move.target.id, distance, turns_remaining) result.append(fleet) return result
def get_best_planets_to_attack(self, count=1, turns=30, prod_turns=100): planet_score = {} #log.info("Score eval for %s planets" % len(self.universe.not_my_planets)) for planet_to_attack in self.universe.not_my_planets: log.info("Score eval for %s" % planet_to_attack) planet_score[planet_to_attack] = 0 enemy_ships_enroute = self.enemy_ships_attacking(planet_to_attack) if planet_to_attack.owner == player.NOBODY \ else self.enemy_ships_reinforcing(planet_to_attack) planet_to_attack_future = planet_to_attack.in_future(turns) if planet_to_attack_future.owner == player.ME: continue my_nearest_planets = sorted( self.universe.my_planets, key=lambda p: p.distance(planet_to_attack) + p.id / 1000000.0) for source in my_nearest_planets: log.info("Score eval source %s" % source) distance = source.distance(planet_to_attack) if self.ships_available[source] <= 0 or distance >= turns: continue # if planet_to_attack.owner == player.NOBODY and \ # distance > (self.closest_enemy_planet_distance(planet_to_attack) * ATTACK_PROXIMITY_RATIO): # continue fleet_to_send = Fleet(self.universe, 12345, 1, self.ships_available[source], source.id, planet_to_attack.id, distance, distance) planet_to_attack_future = planet_to_attack.in_future( turns, fleet_to_send) if planet_to_attack_future.owner != player.ME: continue min_ships_to_send = 1 if len(planet_to_attack.attacking_fleets) == 0: min_ships_to_send = planet_to_attack.ship_count + 1 for ships_to_send in range(1, self.ships_available[source] + 1, 1): fleet_to_send = Fleet(self.universe, 12345, 1, ships_to_send, source.id, planet_to_attack.id, distance, distance) planet_to_attack_future = planet_to_attack.in_future( turns, fleet_to_send) if planet_to_attack_future.owner == player.ME: planet_score[planet_to_attack] = planet_to_attack_future.ship_count - ships_to_send + \ (prod_turns-distance)*planet_to_attack.growth_rate + enemy_ships_enroute break #log.info("Score eval from %s is %s" % (source, planet_score[planet_to_attack] )) if planet_score[planet_to_attack] > 0: break sorted_planets = sorted( self.universe.not_my_planets, key=lambda p: planet_score[p] + p.id / 1000000.0, reverse=True) result = sorted_planets[:count] if count < len( sorted_planets) else sorted_planets filtered_result = [] for p in result: if planet_score[p] > 0 or self.my_total_ships >= ( 2 * self.enemy_total_ships): filtered_result.append(p) for p in filtered_result: if planet_score[p] > 0: log.info("Score for %s is %s" % (p, planet_score[p])) log.info("Score eval done: %s planets" % len(result)) return filtered_result