def main(): map_data = '' while(True): current_line = raw_input() if len(current_line) >= 2 and current_line.startswith("go"): log.startTurn() log.stop() pw = PlanetWars(map_data) DoTurn3(pw) pw.FinishTurn() map_data = '' log.start() log.debug('finished turn') else: map_data += current_line + '\n'
def getBestOrders1(gains, availableShips, pw): log.start() #gains: dict, key = planetId, list of (ships required, gain, other planetID()) #available ships: dict, key = planetId, int of available ships for attacking orders = [] #list of (source planetId, destinationPlanetId, number of attackers) for planet in availableShips: log.debug('planet: ' + str(planet) + ' available ships: ' + str(availableShips[planet])) log.debug('gains: \n' + '\n'.join([str(x) for x in gains[planet]])) if availableShips[planet] == 0: continue # should probably do some recursive optimization crazyness here... if gains[planet][0][0] < availableShips[planet]: orders.append((planet, gains[planet][0][2], gains[planet][0][0])) log.debug('getBestOrders1 returning : ' + str(orders)) log.stop() return orders
def getBestOrders2(gains, availableShips, pw): log.start() #gains: dict, key = planetId, list of (ships required, gain, other planetID()) #available ships: dict, key = planetId, int of available ships for attacking orders = [] #list of (source planetId, destinationPlanetId, number of attackers) for planet in availableShips: log.debug('planet: ' + str(planet) + ' available ships: ' + str(availableShips[planet])) log.debug('gains: \n' + '\n'.join([str(x) for x in gains[planet]])) if len(gains[planet]) == 0: log.debug('no planets left to conquer?') continue if availableShips[planet] == 0: continue # should probably do some recursive optimization crazyness here... if gains[planet][0][0] < availableShips[planet]: previousDistance = orderAlreadyPlaced(orders, gains[planet][0][2], pw) log.debug('orders: ' + str(orders)) log.debug('order to place: ' + str((planet, gains[planet][0][2], gains[planet][0][0]))) log.debug('previous distance: ' + str(previousDistance)) if previousDistance is None: orders.append((planet, gains[planet][0][2], gains[planet][0][0])) #if there has already been an order placed, choose the one that's closest if previousDistance < pw.Distance(planet, gains[planet][0][2]): # do nothing, the previous one is better pass else: # replace the order to be sent from the current planet, with the current fleet size(since it may vary due to different distance) for i in range(len(orders)): if orders[i][1] == gains[planet][0][2]: orders[i] = (planet, gains[planet][0][2], gains[planet][0][0]) log.debug('getBestOrders2 returning : ' + str(orders)) log.stop() return orders
// the state of the game, including information about all planets and fleets // that currently exist. Inside this function, you issue orders using the // pw.IssueOrder() function. For example, to send 10 ships from planet 3 to // planet 8, you would say pw.IssueOrder(3, 8, 10). // // There is already a basic strategy in place here. You can use it as a // starting point, or you can throw it out entirely and replace it with your // own. Check out the tutorials and articles on the contest website at // http://www.ai-contest.com/resources. """ from PlanetWars import PlanetWars import FirstTurn from DebugLog import log log.stop() turn_number = 0 turns_ahead = 20 #for gain extra_ships = 1 #1 more than neccessary to take over a planet 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: