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