Ejemplo n.º 1
0
def collectsteel(g, sink, radius, type):  
  total = 0
  
  print 'Looking for planets with excess steel within %f of %s.' % (
    radius, sink.name)
  for p in g.planets:
    if p.planetid != sink.planetid and sink.distance_to(p) <= radius:
      p.load()
      surplus = 1
      while p.can_build({type: surplus}):
        surplus += 1
      surplus -= 1
      if surplus > 0:
        fleet = p.build_fleet({type: surplus},
                              interactive=False,
                              skip_check=True)
        if fleet:
          total += surplus
          fleet.move_to_planet(sink)
        else:
          print "build failed."
          
  
  value = game.ship_cost({type: total})
  print "collected %d steel" % value['steel']
Ejemplo n.º 2
0
def buildmerchantmen(g, level):
  """Build merchants at new planets that could have built an arc but didn't"""
  merchant = {'merchantmen': 1}
  arc = {'arcs': 1}
  arc_cost = game.ship_cost(arc)

  print 'Looking for planets younger than %d to build merchantmen.' % level
  print 'Name, ID, Society, Money, Antimatter, Steel'
  for p in g.planets:
    p.load()
    if p.society < level and p.steel[0] > arc_cost['steel']:
      neighbors = None
      if p.can_build(merchant):
        neighbors = g.my_planets_near(p)
        print '"%s", %d, %d, %d, %d, %d' % (
          p.name, p.planetid, p.society, p.money, p.antimatter[0], p.steel[0]
        )
      while p.can_build(merchant) and len(neighbors) > 0:
        try:
          fleet = p.build_fleet(merchant,
                                interactive=False,
                                skip_check=True)
          sink = neighbors.pop(0)['planet']
          print "moving %d to %s" % (fleet.fleetid, sink.name)
          fleet.move_to_planet(sink)
        except:
          # something blew up, move on
          neighbors = []