def DoTurn(pw): try: # (1) If we currently have a fleet in flight, just do nothing. if len(pw.MyFleets()) >= 3: log.debug('Returning since more than 2 fleets are out') return # (2) Find my strongest planet. source = -1 source_score = -999999.0 source_num_ships = 0 my_planets = pw.MyPlanets() for p in my_planets: score = float(p.NumShips()) if score > source_score: source_score = score source = p.PlanetID() source_num_ships = p.NumShips() # (3) Find the weakest enemy or neutral planet. dest = -1 dest_score = -999999.0 not_my_planets = pw.NotMyPlanets() for p in not_my_planets: score = 1.0 / (1 + p.NumShips()) if score > dest_score: dest_score = score dest = p.PlanetID() # (4) Send half the ships from my strongest planet to the weakest # planet that I do not own. if source >= 0 and dest >= 0: num_ships = source_num_ships / 2 pw.IssueOrder(source, dest, num_ships) except Exception, e: log.error(str(e))
def PlanetWorthinessToTakeOver(myPlanet, otherPlanet, minFleetSize, distance): try: enemyLoss = int(otherPlanet.Owner() == 2) * otherPlanet.GrowthRate() growthRate = otherPlanet.GrowthRate() log.debug('enemy loss: ' + str(enemyLoss)) log.debug('growth rate: ' + str(growthRate)) log.debug('min fleet size: ' + str(minFleetSize)) result = 1.0 * (growthRate + enemyLoss) / (minFleetSize * ( 1.0 + distance)**2.0) log.debug('result of planet worthiness: ' + str(result)) return result except Exception, e: log.exc(e) log.error('due to error, PlanetWorthinessToTakeOver() will return 0') return 0.0