Commits

David Jones committed af0bd0c

cleaning up.

Comments (0)

Files changed (1)

 
 
 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
+  they belong.
+  """
   result = [make_empty_arrays(max_turn) for p in planets]
   for f in fleets:
     if f.turns_remaining < max_turn:
   return result
 
 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.
+  """
+
   turn = 0
   i = 0
   owner, ships, rate = planet.owner, planet.num_ships, planet.growth_rate
     counts = [0,mine[t] ,enemy[t]]
     counts[owner] += ships
     owner,ships = resolve(counts,owner)
-
-
-
   return result
 
 def log_game_state(futures,fleets):
 
 
 def find_available_conservative(future, rate, owner=1):
-  """find the number I can send without losing a planet
-  too quick."""
+  """
+  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
+  number of enemy ships.
+
+  Consider sending ships starting from the last turn
+  which I take control.
+
+  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][2]
   tmp[i] = max(t,0)      
-
-
-  # debug("tmp: %s", tmp)
   return  tmp
 
-def update_available(available, futures, pw, owner=1):
-  for idx in xrange(len(pw.planets)):
-    if available[idx] is None: continue
-    for n in available:
-      if n > 0:
-        break
-    else:
-      # never anything to do here
-      continue
-    av = available[idx]
-    closest_en = len(av)
-    # find the quickest an enemy can get here.
-    for (d,n) in pw.planets[idx].neighbors:
-      if d >= closest_en: break
-      if n == idx: continue
-
-      fut = futures[n]
-      for i in xrange(1,len(fut)):
-        if fut[1] > 0 and fut[1] != owner:
-          tmp = i + d - 1
-          if tmp < closest_en:
-            closest_en = tmp
-      
-    for i in xrange(closest_en, len(av)):
-      av[i] = 0
-      
-
-def find_number_on_aggressive(pw, futures, idx, owner):
-  max_turn = len(futures[1])
-  res = [0] * max_turn
-  
-  np = len(futures)
-  dst = idx
-  for (dist, src) in pw.planets[idx].neighbors:
-    future = futures[src]
-    if src == dst: continue
-    best = 0
-    for t in xrange(1,max_turn-dist):
-      junk,o,n = future[t]
-      if o == owner and n > best:
-        best = n
-      res[t+dist-1] += best
-  return res
 
 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
+  launch from.
+  """
   np = len(pw.planets)
   if srcs is None:
     srcs = [n for n in xrange(np)]
   res = [0] * max_turn
 
   dst = idx
+
+  # 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:
     if src == dst: continue
     av = available[src]
     for t in xrange(1,max_turn-dist):
       res[t+dist-1] += av[t]
 
+  # 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)):
     res[i] += res[i-1]
-  # debug_int_list("    turn:", range(len(result[1])))
-  # debug_int_list("my_on[1]:", result[1])
   return res
 
 
-
 class Analysis:
+  """
+  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.
+    """
     if pw is None:
       pass
     else:
         self.max_turn = find_max_distance(pw,first_turn) + 2
 
       self.pidx = xrange(len(pw.planets))
-
-      self.reserved = [[0] * self.max_turn for p in self.pidx]
       self.shots = []
       self.orders = []
 
                          for idx 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)    
-    
 
   def score_growth(self):
     values = [(self.futures[i][-1][1], self.pw.planets[i].growth_rate)
     # if do_debug:
     #   debug_list("fleets", self.pw.fleets)
 
-  def update_available(self):
-    for p in self.pidx:
-      if self.available[p] == None: continue
-      for en_turn in xrange(self.max_turn):
-        if en_on[en_turn] > 0: break
-    
   def move_forward(self):
     futures = self.futures
     srcs = [i for i in self.pidx