def load_fleets(planets, fleets,max_turn):
+ Load all the inciming fleets into some arrays.
+ For each planet, create a list from make_empty_arrays.
+ Then, for each fleet incoming to the planet, add
+ the ships for the fleet to the appropriate turn.
+ At least, this is what the output looks like. Instead,
+ just loop through the fleets and add the ships where
result = [make_empty_arrays(max_turn) for p in planets]
if f.turns_remaining < max_turn:
def run_planet(planet, fleets):
+ Calculate the future state of a planet based on the incoming fleets.
+ Returns a list of (turn number, owner, number of ships) tuples.
+ The first element of the list is always (0, owner#, 0). This
+ helps (or helped at one point) with other calculations.
owner, ships, rate = planet.owner, planet.num_ships, planet.growth_rate
counts = [0,mine[t] ,enemy[t]]
owner,ships = resolve(counts,owner)
def find_available_conservative(future, rate, owner=1):
- """find the number I can send without losing a planet
+ Find the number of ships to send from a planet without
+ losing it to ships already on the way.
+ Don't even consider stuff that I don't own at the end
+ of the future. My assumption here is that the ships
+ are better off staying still and reducing the
+ Consider sending ships starting from the last turn
+ TODO: describe the code for finding available...
# don't mess with stuff that I don't own the whole time.
# debug("trying to find future: %s", future)
t += future[first_turn]
- # debug("tmp: %s", tmp)
-def update_available(available, futures, pw, owner=1):
- for idx in xrange(len(pw.planets)):
- if available[idx] is None: continue
- # never anything to do here
- # find the quickest an enemy can get here.
- for (d,n) in pw.planets[idx].neighbors:
- if d >= closest_en: break
- for i in xrange(1,len(fut)):
- if fut > 0 and fut != owner:
- for i in xrange(closest_en, len(av)):
-def find_number_on_aggressive(pw, futures, idx, owner):
- max_turn = len(futures)
- for (dist, src) in pw.planets[idx].neighbors:
- if src == dst: continue
- for t in xrange(1,max_turn-dist):
- if o == owner and n > best:
def find_number_on_available(pw, available, idx, max_turn,srcs=None):
+ Find the number of ships I can get on planet idx given the list
+ of available ships from find_available_conservative.
+ srcs can be specified to limit the planets which I can
srcs = [n for n in xrange(np)]
+ # For each neighbor, besides the same planet,
+ # add the available ships on each turn to the
+ # turn + distance of the arrival planet.
for (dist, src) in pw.planets[idx].neighbors:
for t in xrange(1,max_turn-dist):
+ # Now, convert it so the value at res[i] is the total
+ # than can land at or before turn i.
for i in xrange(1,len(res)):
- # debug_int_list(" turn:", range(len(result)))
- # debug_int_list("my_on:", result)
+ This is where all the game logic lies. I pulled this class
+ from the original heuristic bots.
def __init__(self, pw=None,first_turn=None, max_turn=None, end_time=None):
+ This is set up so that it can be copied.
self.max_turn = find_max_distance(pw,first_turn) + 2
self.pidx = xrange(len(pw.planets))
- self.reserved = [ * self.max_turn for p in self.pidx]
- # update_available(self.my_available, self.futures, self.pw, owner=1)
- # update_available(self.my_available, self.futures, self.pw, owner=2)
values = [(self.futures[i][-1], self.pw.planets[i].growth_rate)
# debug_list("fleets", self.pw.fleets)
- def update_available(self):
- if self.available[p] == None: continue
- for en_turn in xrange(self.max_turn):
- if en_on[en_turn] > 0: break
srcs = [i for i in self.pidx