本文整理汇总了Python中planetwars.planet.Planet类的典型用法代码示例。如果您正苦于以下问题:Python Planet类的具体用法?Python Planet怎么用?Python Planet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Planet类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doPrep
def doPrep(self):
log.info("Prep phase")
self.max_distance_between_planets = 0
for p1 in self.all_planets:
for p2 in self.all_planets:
self.max_distance_between_planets = max(self.max_distance_between_planets, p1.distance(p2))
#log.info("Max distance: %s" % self.max_distance_between_planets)
# calculate current high level metrics
self.my_total_ships_available = 0
self.my_total_ships = 0
self.my_total_growth_rate = 0
self.enemy_total_ships_available = 0
self.enemy_total_ships = 0
self.enemy_total_growth_rate = 0
self.ships_available = {}
self.ships_needed = {}
self.planet_timeline = {}
for planet in self.all_planets:
if len(planet.attacking_fleets) == 0:
self.ships_available[planet] = planet.ship_count
self.ships_needed[planet] = 0
simulation_distance = self.max_distance_between_planets
self.planet_timeline[planet] = planet.in_future_timeline(simulation_distance)
else:
simulation_distance = self.max_distance_between_planets
self.planet_timeline[planet] = planet.in_future_timeline(simulation_distance)
max_needed = 0
min_available = 1000000
#log.info("timeline for %s: %s" % (planet, self.planet_timeline[planet]))
for step in self.planet_timeline[planet]:
owner = step[0]
ship_count = step[1]
if owner != planet.owner:
max_needed = max(max_needed, ship_count)
else:
min_available = min(min_available, ship_count)
if max_needed > 0:
# do we bail if we are going to lose this planet anyway?
self.ships_available[planet] = 0
self.ships_needed[planet] = max_needed
else:
self.ships_available[planet] = min_available
self.ships_needed[planet] = 0
if (planet.owner == player.ME):
self.my_total_ships_available += self.ships_available[planet]
self.my_total_growth_rate += planet.growth_rate
self.my_total_ships += planet.ship_count
else:
self.enemy_total_ships_available += self.ships_available[planet]
self.enemy_total_growth_rate += planet.growth_rate
self.enemy_total_ships += planet.ship_count
#log.info("avail ships for %s: %s" % (planet, self.ships_available[planet]))
# prevent initial overexpansion
if self.universe.game.turn_count <= 2:
for my_planet in self.my_planets:
for enemy_planet in self.enemy_planets:
max_enemy_fleet = self.ships_available[enemy_planet]
distance = my_planet.distance(enemy_planet)
ships_needed_for_safety = max_enemy_fleet-distance*my_planet.growth_rate
if ships_needed_for_safety > (my_planet.ship_count - self.ships_available[my_planet]):
deficit = ships_needed_for_safety - (my_planet.ship_count - self.ships_available[my_planet])
#log.info("deficit for %s: %s" % (my_planet, deficit))
if deficit > self.ships_available[my_planet]:
deficit = self.ships_available[my_planet]
self.ships_available[my_planet] -= deficit
self.my_total_ships_available -= deficit
self.my_total_ships += self.total_fleet_ship_count(player.ME)
self.enemy_total_ships += self.total_fleet_ship_count(player.NOT_ME)
# calculate enemy's center of mass
weighted_x = 0
weighted_y = 0
div = 0
for planet in self.enemy_planets:
weighted_x += planet.position.x * (self.ships_available[planet] + planet.growth_rate)
weighted_y += planet.position.y * (self.ships_available[planet] + planet.growth_rate)
div += self.ships_available[planet] + planet.growth_rate
if div == 0:
div = 1
self.enemy_com = Planet(self.universe, 666, weighted_x/div, weighted_y/div, 2, 0, 0)
weighted_x = 0
weighted_y = 0
div = 0
for planet in self.enemy_planets:
weighted_x += planet.position.x * (planet.growth_rate+1)
weighted_y += planet.position.y * (planet.growth_rate+1)
div += planet.growth_rate+1
self.enemy_growth_com = Planet(self.universe, 666, weighted_x/div, weighted_y/div, 2, 0, 0)
# For every planet, and every turn, calculate how many ships the enemy CAN sent to it's aid
self.max_aid_at_turn = {}
self.max_aid_at_turn_single = {}
#.........这里部分代码省略.........
示例2: MyBot
#.........这里部分代码省略.........
self.enemy_total_ships += planet.ship_count
#log.info("avail ships for %s: %s" % (planet, self.ships_available[planet]))
# prevent initial overexpansion
if self.universe.game.turn_count <= 2:
for my_planet in self.my_planets:
for enemy_planet in self.enemy_planets:
max_enemy_fleet = self.ships_available[enemy_planet]
distance = my_planet.distance(enemy_planet)
ships_needed_for_safety = max_enemy_fleet-distance*my_planet.growth_rate
if ships_needed_for_safety > (my_planet.ship_count - self.ships_available[my_planet]):
deficit = ships_needed_for_safety - (my_planet.ship_count - self.ships_available[my_planet])
#log.info("deficit for %s: %s" % (my_planet, deficit))
if deficit > self.ships_available[my_planet]:
deficit = self.ships_available[my_planet]
self.ships_available[my_planet] -= deficit
self.my_total_ships_available -= deficit
self.my_total_ships += self.total_fleet_ship_count(player.ME)
self.enemy_total_ships += self.total_fleet_ship_count(player.NOT_ME)
# calculate enemy's center of mass
weighted_x = 0
weighted_y = 0
div = 0
for planet in self.enemy_planets:
weighted_x += planet.position.x * (self.ships_available[planet] + planet.growth_rate)
weighted_y += planet.position.y * (self.ships_available[planet] + planet.growth_rate)
div += self.ships_available[planet] + planet.growth_rate
if div == 0:
div = 1
self.enemy_com = Planet(self.universe, 666, weighted_x/div, weighted_y/div, 2, 0, 0)
weighted_x = 0
weighted_y = 0
div = 0
for planet in self.enemy_planets:
weighted_x += planet.position.x * (planet.growth_rate+1)
weighted_y += planet.position.y * (planet.growth_rate+1)
div += planet.growth_rate+1
self.enemy_growth_com = Planet(self.universe, 666, weighted_x/div, weighted_y/div, 2, 0, 0)
# For every planet, and every turn, calculate how many ships the enemy CAN sent to it's aid
self.max_aid_at_turn = {}
self.max_aid_at_turn_single = {}
enemy_planets_incl_candidates = list(self.enemy_planets) + self.get_neutrals_under_enemy_attack()
for planet in self.all_planets:
self.max_aid_at_turn[planet] = {}
self.max_aid_at_turn_single[planet] = {}
for turn in range(1, self.max_distance_between_planets+1):
max_aid = 0
max_aid_single = 0
#for enemy_planet in self.all_planets:
for enemy_planet in enemy_planets_incl_candidates:
if enemy_planet.id != planet.id and planet.distance(enemy_planet) < turn:
enemy_planet_time_step = self.planet_timeline[enemy_planet][turn - planet.distance(enemy_planet)]
if (enemy_planet_time_step[0] in player.ENEMIES):
max_aid += enemy_planet_time_step[1]
max_aid_single = max(max_aid_single, enemy_planet_time_step[1])
#log.info("adding to max aid: %s" % enemy_planet_time_step[1])
else:
if enemy_planet.id != planet.id and planet.distance(enemy_planet) == turn:
enemy_planet_time_step = self.planet_timeline[enemy_planet][0]
if (enemy_planet_time_step[0] in player.ENEMIES):
示例3: MyBot
#.........这里部分代码省略.........
# if planet.id == 14:
# log.info("avail timeline for %s is: %s" % (planet, self.ships_available_at_turn[planet]))
self.total_ships[PLAYER1] += self.total_fleet_ship_count(PLAYER1)
self.total_ships[PLAYER2] += self.total_fleet_ship_count(PLAYER2)
for my_planet in [self.my_home]:
for enemy_planet in [self.enemy_home]:
# if self.ships_available_at_turn[enemy_planet][0] < self.ships_available_at_turn[my_planet][0]:
# continue
if my_planet.owner != PLAYER1 or enemy_planet.owner != PLAYER2:
continue
max_enemy_fleet = self.ships_available_at_turn[enemy_planet][0]
distance = my_planet.distance(enemy_planet)
ships_needed_for_safety = max_enemy_fleet-(self.planet_timeline[my_planet][distance-1][1] - my_planet.ship_count) - enemy_planet.growth_rate
#ships_needed_for_safety = max_enemy_fleet-(self.planet_timeline[my_planet][distance-1][1] - my_planet.ship_count)
if ships_needed_for_safety > (my_planet.ship_count - self.ships_available_at_turn[my_planet][0]):
deficit = ships_needed_for_safety - (my_planet.ship_count - self.ships_available_at_turn[my_planet][0])
#log.info("deficit for %s: %s, max enemy fleet %s" % (my_planet, deficit, max_enemy_fleet))
if deficit > self.ships_available_at_turn[my_planet][0]:
deficit = self.ships_available_at_turn[my_planet][0]
self.decrease_ships_available(my_planet, 0, deficit)
# calculate enemy's center of mass
weighted_x = 0
weighted_y = 0
div = 0
for planet in self.enemy_planets:
weighted_x += planet.position.x * (self.ships_available_at_turn[planet][0] + planet.growth_rate)
weighted_y += planet.position.y * (self.ships_available_at_turn[planet][0] + planet.growth_rate)
div += self.ships_available_at_turn[planet][0] + planet.growth_rate
if div == 0:
div = 1
self.enemy_com = Planet(self.universe, 666, weighted_x/div, weighted_y/div, 2, 0, 0)
# For every planet, and every turn, calculate how many ships each player can send to it
# TODO should we use ships_available_at_turn here?
self.max_aid_at_turn = {PLAYER1:{}, PLAYER2:{}}
for player in (PLAYER1 | PLAYER2):
source_planets = list(self.universe.find_planets(player)) + self.get_neutrals_under_player_attack(player)
for planet in self.all_planets:
self.max_aid_at_turn[player][planet] = {}
for turn in range(1, self.max_distance_between_planets+21):
max_aid = 0
for source_planet in source_planets:
if source_planet.id != planet.id and planet.distance(source_planet) < turn:
source_planet_time_step = self.planet_timeline[source_planet][turn - planet.distance(source_planet) - 1]
if (source_planet_time_step[0] == player):
#log.info("Max aid by %s for %s from %s at %s: %s" % (player.id, planet.id, source_planet.id, turn, source_planet_time_step[1]))
max_aid += source_planet_time_step[1]
else:
if source_planet.id != planet.id and planet.distance(source_planet) == turn:
if (source_planet.owner == player):
max_aid += source_planet.ship_count
self.max_aid_at_turn[player][planet][turn] = max_aid
#log.info("Max aid by %s for %s at %s: %s" % (player.id, planet.id, turn, self.max_aid_at_turn[player][planet][turn]))
log.info("MY STATUS: %s/%s" % (self.total_ships[PLAYER1], self.total_growth_rate[PLAYER1]))
log.info("ENEMY STATUS: %s/%s" % (self.total_ships[PLAYER2], self.total_growth_rate[PLAYER2]))
def doDefense(self):
log.info("Defense phase")
for planet_to_defend in self.all_planets:
ships_to_send = self.ships_needed[planet_to_defend]
if ships_to_send <= 0:
示例4: __init__
def __init__(self, universe, id, x, y, owner, ship_count, growth_rate):
Planet.__init__(self, universe, id, x, y, owner, ship_count, growth_rate)
self._future_cache = [copy(self)]
示例5: doPrep
def doPrep(self):
log.info("Prep phase")
if self.current_turn == 1:
self.my_home = list(self.my_planets)[0]
self.enemy_home = list(self.enemy_planets)[0]
self.max_distance_between_planets = 0
for p1 in self.all_planets:
for p2 in self.all_planets:
self.max_distance_between_planets = max(self.max_distance_between_planets, p1.distance(p2))
#log.info("Max distance: %s" % self.max_distance_between_planets)
# calculate current high level metrics
self.total_ships = {PLAYER1:0, PLAYER2:0}
self.total_growth_rate = {PLAYER1:0, PLAYER2:0}
self.ships_available_at_turn = {}
self.ships_needed = {}
self.ships_needed_at_turn = {}
self.ships_needed_later = {}
self.planet_timeline = {}
for planet in self.all_planets:
self.ships_available_at_turn[planet] = {}
scheduled_fleets_to_planet = self.get_scheduled_fleets_to(planet)
scheduled_fleets_from_planet = self.get_scheduled_fleets_from(planet)
self.planet_timeline[planet] = planet.in_future_timeline(self.max_distance_between_planets + 20, scheduled_fleets_to_planet, scheduled_fleets_from_planet)
need_help = False
if planet.id == 7:
log.info("timeline for %s: %s" % (planet, self.planet_timeline[planet]))
#log.info("attacking fleets by me: %s" % (self.universe.find_fleets(PLAYER1, destination=planet)))
prev_owner = planet.owner
for step in self.planet_timeline[planet]:
owner = step[0]
ship_count = step[1]
if owner != prev_owner and prev_owner == planet.owner and prev_owner != NOBODY and not need_help:
self.ships_needed[planet] = ship_count
self.ships_needed_at_turn[planet] = self.planet_timeline[planet].index(step) + 1
need_help = True
self.ships_needed_later[planet] = []
#log.info("Planet %s needs help %s at %s" % (planet, ship_count, self.ships_needed_at_turn[planet]))
prev_owner = owner
if not need_help:
self.ships_needed[planet] = 0
min_available = 1000000
step_index = len(self.planet_timeline[planet])
for step in reversed(self.planet_timeline[planet]):
ship_count = step[1]
min_available = min(min_available, ship_count)
if step[0] == NOBODY:
min_available = 0
if min_available < 0:
log.info("Negative min_available: %s for %s" % (min_available, planet))
min_available = 0
self.ships_available_at_turn[planet][step_index] = min_available
#log.info("avail for %s at %s: %s" % (planet, step_index, min_available))
step_index -= 1
self.ships_available_at_turn[planet][0] = max(0,min(planet.ship_count, self.ships_available_at_turn[planet][1] - planet.growth_rate))
else:
for step_index in range(0, len(self.planet_timeline[planet])+1):
self.ships_available_at_turn[planet][step_index] = 0
if planet.owner != NOBODY:
self.total_ships[planet.owner] += planet.ship_count
self.total_growth_rate[planet.owner] += planet.growth_rate
# if planet.id == 14:
# log.info("avail timeline for %s is: %s" % (planet, self.ships_available_at_turn[planet]))
self.total_ships[PLAYER1] += self.total_fleet_ship_count(PLAYER1)
self.total_ships[PLAYER2] += self.total_fleet_ship_count(PLAYER2)
for my_planet in [self.my_home]:
for enemy_planet in [self.enemy_home]:
# if self.ships_available_at_turn[enemy_planet][0] < self.ships_available_at_turn[my_planet][0]:
# continue
if my_planet.owner != PLAYER1 or enemy_planet.owner != PLAYER2:
continue
max_enemy_fleet = self.ships_available_at_turn[enemy_planet][0]
distance = my_planet.distance(enemy_planet)
ships_needed_for_safety = max_enemy_fleet-(self.planet_timeline[my_planet][distance-1][1] - my_planet.ship_count) - enemy_planet.growth_rate
#ships_needed_for_safety = max_enemy_fleet-(self.planet_timeline[my_planet][distance-1][1] - my_planet.ship_count)
if ships_needed_for_safety > (my_planet.ship_count - self.ships_available_at_turn[my_planet][0]):
deficit = ships_needed_for_safety - (my_planet.ship_count - self.ships_available_at_turn[my_planet][0])
#log.info("deficit for %s: %s, max enemy fleet %s" % (my_planet, deficit, max_enemy_fleet))
if deficit > self.ships_available_at_turn[my_planet][0]:
deficit = self.ships_available_at_turn[my_planet][0]
self.decrease_ships_available(my_planet, 0, deficit)
# calculate enemy's center of mass
weighted_x = 0
weighted_y = 0
div = 0
for planet in self.enemy_planets:
weighted_x += planet.position.x * (self.ships_available_at_turn[planet][0] + planet.growth_rate)
weighted_y += planet.position.y * (self.ships_available_at_turn[planet][0] + planet.growth_rate)
div += self.ships_available_at_turn[planet][0] + planet.growth_rate
if div == 0:
div = 1
self.enemy_com = Planet(self.universe, 666, weighted_x/div, weighted_y/div, 2, 0, 0)
# For every planet, and every turn, calculate how many ships each player can send to it
# TODO should we use ships_available_at_turn here?
#.........这里部分代码省略.........
示例6: __init__
def __init__(self, universe, id, x, y, owner, ship_count, growth_rate):
Planet.__init__(self, universe, id, x, y, owner, ship_count, growth_rate)
self._future_cache = [copy(self)]
self.dist_closest_enemy = (-1,0) #turn, value
self.dist_closest_mine = (-1,0)
self._score_cache = {}
示例7: doPrep
def doPrep(self):
log.info("Prep phase")
self.max_distance_between_planets = 0
for p1 in self.all_planets:
for p2 in self.all_planets:
self.max_distance_between_planets = max(self.max_distance_between_planets, p1.distance(p2))
#log.info("Max distance: %s" % self.max_distance_between_planets)
# calculate current high level metrics
self.total_ships = {PLAYER1:0, PLAYER2:0}
self.total_growth_rate = {PLAYER1:0, PLAYER2:0}
self.ships_available = {}
self.ships_needed = {}
self.ships_needed_at_turn = {}
self.planet_timeline = {}
for planet in self.all_planets:
scheduled_fleets_to_planet = self.get_scheduled_fleets_to(planet)
scheduled_fleets_from_planet = self.get_scheduled_fleets_from(planet)
self.planet_timeline[planet] = planet.in_future_timeline(self.max_distance_between_planets + 20, scheduled_fleets_to_planet, scheduled_fleets_from_planet)
need_help = False
min_available = 1000000
#log.info("timeline for %s: %s" % (planet, self.planet_timeline[planet]))
prev_owner = planet.owner
for step in self.planet_timeline[planet]:
owner = step[0]
ship_count = step[1]
if owner == PLAYER2 and prev_owner == PLAYER1 and not need_help:
self.ships_needed[planet] = ship_count
self.ships_needed_at_turn[planet] = self.planet_timeline[planet].index(step) + 1
need_help = True
log.info("Planet %s needs help %s at %s" % (planet, ship_count, self.ships_needed_at_turn[planet]))
if owner == planet.owner:
min_available = min(min_available, ship_count)
if min_available < 0:
log.info("Negative min_available: %s for %s" % (min_available, planet))
min_available = 0
prev_owner = owner
if need_help:
self.ships_available[planet] = 0
else:
self.ships_available[planet] = min(min_available, planet.ship_count)
self.ships_needed[planet] = 0
if planet.owner != NOBODY:
self.total_ships[planet.owner] += planet.ship_count
self.total_growth_rate[planet.owner] += planet.growth_rate
self.total_ships[PLAYER1] += self.total_fleet_ship_count(PLAYER1)
self.total_ships[PLAYER2] += self.total_fleet_ship_count(PLAYER2)
if self.universe.game.turn_count <= 2:
for my_planet in self.my_planets:
for enemy_planet in self.enemy_planets:
max_enemy_fleet = self.ships_available[enemy_planet]
distance = my_planet.distance(enemy_planet)
ships_needed_for_safety = max_enemy_fleet-distance*my_planet.growth_rate
if ships_needed_for_safety > (my_planet.ship_count - self.ships_available[my_planet]):
deficit = ships_needed_for_safety - (my_planet.ship_count - self.ships_available[my_planet])
#log.info("deficit for %s: %s" % (my_planet, deficit))
if deficit > self.ships_available[my_planet]:
deficit = self.ships_available[my_planet]
self.ships_available[my_planet] -= deficit
# calculate enemy's center of mass
weighted_x = 0
weighted_y = 0
div = 0
for planet in self.enemy_planets:
weighted_x += planet.position.x * (self.ships_available[planet] + planet.growth_rate)
weighted_y += planet.position.y * (self.ships_available[planet] + planet.growth_rate)
div += self.ships_available[planet] + planet.growth_rate
if div == 0:
div = 1
self.enemy_com = Planet(self.universe, 666, weighted_x/div, weighted_y/div, 2, 0, 0)
# For every planet, and every turn, calculate how many ships each player can send to it
self.max_aid_at_turn = {PLAYER1:{}, PLAYER2:{}}
for player in (PLAYER1 | PLAYER2):
source_planets = list(self.universe.find_planets(player)) + self.get_neutrals_under_player_attack(player)
for planet in self.all_planets:
self.max_aid_at_turn[player][planet] = {}
for turn in range(1, self.max_distance_between_planets+21):
max_aid = 0
for source_planet in source_planets:
if source_planet.id != planet.id and planet.distance(source_planet) < turn:
source_planet_time_step = self.planet_timeline[source_planet][turn - planet.distance(source_planet)]
if (source_planet_time_step[0] == player):
max_aid += source_planet_time_step[1]
else:
if source_planet.id != planet.id and planet.distance(source_planet) == turn:
source_planet_time_step = self.planet_timeline[source_planet][0]
if (source_planet_time_step[0] == player):
max_aid += source_planet.ship_count
self.max_aid_at_turn[player][planet][turn] = max_aid
#log.info("Max aid by %s for %s at %s: %s" % (player.id, planet.id, turn, self.max_aid_at_turn[player][planet][turn]))
log.info("MY STATUS: %s/%s" % (self.total_ships[PLAYER1], self.total_growth_rate[PLAYER1]))
#.........这里部分代码省略.........
示例8: MyBot
#.........这里部分代码省略.........
def doPrep(self):
log.info("Prep phase")
self.max_distance_between_planets = 0
for p1 in self.all_planets:
for p2 in self.all_planets:
self.max_distance_between_planets = max(self.max_distance_between_planets, p1.distance(p2))
#log.info("Max distance: %s" % self.max_distance_between_planets)
# calculate current high level metrics
self.total_ships = {PLAYER1:0, PLAYER2:0}
self.total_growth_rate = {PLAYER1:0, PLAYER2:0}
self.ships_available = {}
self.ships_needed = {}
self.ships_needed_at_turn = {}
self.planet_timeline = {}
for planet in self.all_planets:
scheduled_fleets_to_planet = self.get_scheduled_fleets_to(planet)
scheduled_fleets_from_planet = self.get_scheduled_fleets_from(planet)
self.planet_timeline[planet] = planet.in_future_timeline(self.max_distance_between_planets, scheduled_fleets_to_planet, scheduled_fleets_from_planet)
need_help = False
min_available = 1000000
#log.info("timeline for %s: %s" % (planet, self.planet_timeline[planet]))
prev_owner = planet.owner
for step in self.planet_timeline[planet]:
owner = step[0]
ship_count = step[1]
if owner == PLAYER2 and prev_owner == PLAYER1 and not need_help:
self.ships_needed[planet] = ship_count
self.ships_needed_at_turn[planet] = self.planet_timeline[planet].index(step) + 1
need_help = True
log.info("Planet %s needs help %s at %s" % (planet, ship_count, self.ships_needed_at_turn[planet]))
if owner == planet.owner:
min_available = min(min_available, ship_count)
if min_available < 0:
log.info("Negative min_available: %s for %s" % (min_available, planet))
min_available = 0
prev_owner = owner
if need_help:
self.ships_available[planet] = 0
else:
self.ships_available[planet] = min(min_available, planet.ship_count)
self.ships_needed[planet] = 0
if planet.owner != NOBODY:
self.total_ships[planet.owner] += planet.ship_count
self.total_growth_rate[planet.owner] += planet.growth_rate
self.total_ships[PLAYER1] += self.total_fleet_ship_count(PLAYER1)
self.total_ships[PLAYER2] += self.total_fleet_ship_count(PLAYER2)
# calculate enemy's center of mass
weighted_x = 0
weighted_y = 0
div = 0
for planet in self.enemy_planets:
weighted_x += planet.position.x * (self.ships_available[planet] + planet.growth_rate)
weighted_y += planet.position.y * (self.ships_available[planet] + planet.growth_rate)
div += self.ships_available[planet] + planet.growth_rate
if div == 0:
div = 1
self.enemy_com = Planet(self.universe, 666, weighted_x/div, weighted_y/div, 2, 0, 0)
示例9: MyBot
class MyBot(BaseBot):
def total_fleet_ship_count(self, owner):
return sum( [ fleet.ship_count for fleet in self.universe.find_fleets(owner) ] )
def closest_enemy_planet_distance(self, p):
return min((lambda ep:ep.distance(p))(ep) for ep in self.universe.enemy_planets)
def enemy_ships_reinforcing(self, planet, turn):
return sum( [ fleet.ship_count for fleet in planet.reinforcement_fleets if fleet.owner in player.NOT_ME and fleet.turns_remaining <= turn ] )
def doPrep(self):
log.info("Prep phase")
self.max_distance_between_planets = 0
for p1 in self.universe.all_planets:
for p2 in self.universe.all_planets:
self.max_distance_between_planets = max(self.max_distance_between_planets, p1.distance(p2))
#log.info("Max distance: %s" % self.max_distance_between_planets)
# calculate current high level metrics
self.my_total_ships_available = 0
self.my_total_ships = 0
self.my_total_growth_rate = 0
self.enemy_total_ships_available = 0
self.enemy_total_ships = 0
self.enemy_total_growth_rate = 0
self.ships_available = {}
self.ships_needed = {}
self.planet_timeline = {}
for planet in self.universe.all_planets:
if len(planet.attacking_fleets) == 0:
self.ships_available[planet] = planet.ship_count
self.ships_needed[planet] = 0
simulation_distance = self.max_distance_between_planets
self.planet_timeline[planet] = planet.in_future_timeline(simulation_distance)
else:
simulation_distance = self.max_distance_between_planets
self.planet_timeline[planet] = planet.in_future_timeline(simulation_distance)
max_needed = 0
min_available = 1000000
#log.info("timeline for %s: %s" % (planet, self.planet_timeline[planet]))
for step in self.planet_timeline[planet]:
owner = step[0]
ship_count = step[1]
if owner != planet.owner:
max_needed = max(max_needed, ship_count)
else:
min_available = min(min_available, ship_count)
if max_needed > 0:
# do we bail if we are going to lose this planet anyway?
self.ships_available[planet] = 0
self.ships_needed[planet] = max_needed
else:
self.ships_available[planet] = min_available
self.ships_needed[planet] = 0
if (planet.owner == player.ME):
self.my_total_ships_available += self.ships_available[planet]
self.my_total_growth_rate += planet.growth_rate
self.my_total_ships += planet.ship_count
else:
self.enemy_total_ships_available += self.ships_available[planet]
self.enemy_total_growth_rate += planet.growth_rate
self.enemy_total_ships += planet.ship_count
#log.info("avail ships for %s: %s" % (planet, self.ships_available[planet]))
# prevent initial overexpansion
if self.universe.game.turn_count <= 2:
for my_planet in self.universe.my_planets:
for enemy_planet in self.universe.enemy_planets:
max_enemy_fleet = self.ships_available[enemy_planet]
distance = my_planet.distance(enemy_planet)
ships_needed_for_safety = max_enemy_fleet-distance*my_planet.growth_rate
if ships_needed_for_safety > (my_planet.ship_count - self.ships_available[my_planet]):
deficit = ships_needed_for_safety - (my_planet.ship_count - self.ships_available[my_planet])
#log.info("deficit for %s: %s" % (my_planet, deficit))
if deficit > self.ships_available[my_planet]:
deficit = self.ships_available[my_planet]
self.ships_available[my_planet] -= deficit
self.my_total_ships_available -= deficit
self.my_total_ships += self.total_fleet_ship_count(player.ME)
self.enemy_total_ships += self.total_fleet_ship_count(player.NOT_ME)
# calculate enemy's center of mass
weighted_x = 0
weighted_y = 0
div = 0
for planet in self.universe.enemy_planets:
weighted_x += planet.position.x * (self.ships_available[planet] + planet.growth_rate)
weighted_y += planet.position.y * (self.ships_available[planet] + planet.growth_rate)
div += self.ships_available[planet] + planet.growth_rate
if div == 0:
div = 1
self.enemy_com = Planet(self.universe, 666, weighted_x/div, weighted_y/div, 2, 0, 0)
#.........这里部分代码省略.........