my_unassigned_ships.remove(ship)
            defense_distractors.append(ship)

    # handle rogue missions
    if len(rogue_missions_id) > 0:
        for ship_id, target in list(rogue_missions_id.items()):
            ship = game_map.get_me().get_ship(ship_id)
            if ship in my_unassigned_ships:
                orders[ship] = target
                my_unassigned_ships.remove(ship)
            else:
                # the ship died
                planet_ownership_changes[rogue_missions_id[ship_id].id] += 1
                del rogue_missions_id[ship_id]
    elif len(potential_rogue_missions) > 0:
        min_dist_alloc = bot_utils.get_minimal_distance_allocation(
            my_unassigned_ships, potential_rogue_missions)
        rogue_ship = bot_utils.get_shortest_alloc(min_dist_alloc)
        orders[rogue_ship] = min_dist_alloc[rogue_ship]
        my_unassigned_ships.remove(rogue_ship)
        rogue_missions_id[rogue_ship.id] = min_dist_alloc[rogue_ship]
    if len(rogue_missions_id) > 0:
        logging.info(
            f'rogue_missions: {dict([(ship_id, planet.id) for ship_id, planet in rogue_missions_id.items()])}'
        )

    alloc = bot_utils.get_maximal_benefit_allocation(my_unassigned_ships,
                                                     good_opportunities,
                                                     relative_benefit_factors,
                                                     job_base_benefit)
    logging_alloc = {
        f'S{ship.id}': f'P{target.id}'
Beispiel #2
0
                interceptors[enemy].append(ship)
                my_fighting_ships.remove(ship)
                if len(interceptors[enemy]) >= max_response:
                    proximal_enemy_ships.remove(enemy)

    # the rest can build or hunt good opportunities
    temp_alloc = {}
    # temporary - for comparison purposes:
    good_opportunities_copy = copy.deepcopy(good_opportunities)
    for ship in my_fighting_ships:
        if ship not in orders:
            if len(good_opportunities_copy) > 0:
                closest_opportunity = bot_utils.pop_closest(ship, good_opportunities_copy)
                temp_alloc[ship] = closest_opportunity

    minimal_dist_alloc = bot_utils.get_minimal_distance_allocation(my_fighting_ships, good_opportunities)

    logging.info(f'Total dist using old system: {round(bot_utils.total_dist(temp_alloc), 0)}, '
                 f'len: {len(temp_alloc)}')
    logging.info(f'Total dist using new system: {round(bot_utils.total_dist(minimal_dist_alloc), 0)}, '
                 f'len: {len(minimal_dist_alloc)}')

    logging.info(f'Time to calculate minimal distance job allocation: {timer.get_time()} ms')
    for ship in my_fighting_ships:
        if ship in minimal_dist_alloc:
            orders[ship] = minimal_dist_alloc[ship]
        else:
            enemy = bot_utils.get_closest(ship, enemy_ships)
            orders[ship] = enemy

    # create abbreviated order dict for logging
    # 2 STRATEGIC CALCULATIONS & JOB CREATION - output: list good_opportunities
    good_to_dock_planets = \
        [planet for planet in non_full_friendly_planets
         if bot_utils.get_proximity(planet, enemy_ships) > safe_docking_distance + planet.radius]
    logging.info(f'Good planets: {["P"+str(planet.id) for planet in good_to_dock_planets]}')
    logging.info(f'Time used for good planet determination: {timer.get_time()}')

    good_dock_spots = []
    for planet in good_to_dock_planets:
        for _ in range(planet.num_docking_spots - len(planet.all_docked_ships())):
            good_dock_spots.append(planet)

    # 3 JOB ALLOCATION - output: dict orders
    # All orders are placed here - the eventual position may change later on due to position prediction
    orders = {}
    alloc = bot_utils.get_minimal_distance_allocation(my_unassigned_ships, good_to_dock_planets)
    for ship in my_unassigned_ships:
        if ship in alloc:
            orders[ship] = alloc[ship]
        else:
            orders[ship] = ship

    # 5 COMMAND GENERATION
    # prepare avoid_entities list
    all_my_flying_obstacles = [ship for ship in my_fighting_ships]
    avoid_entities = all_planets + all_docked_ships + all_my_flying_obstacles
    for enemy in flying_enemies:
        if enemy in location_prediction:
            avoid_entities.append(location_prediction[enemy])
        else:
            avoid_entities.append(enemy)
Beispiel #4
0
    # All orders are placed here - the eventual position may change later on due to position prediction
    orders = {}

    # handle rogue missions
    if len(rogue_missions_id) > 0:
        for ship_id, target in list(rogue_missions_id.items()):
            ship = game_map.get_me().get_ship(ship_id)
            if ship in my_unassigned_ships:
                orders[ship] = target
                my_unassigned_ships.remove(ship)
            else:
                # the ship died
                planet_ownership_changes[rogue_missions_id[ship_id].id] += 1
                del rogue_missions_id[ship_id]
    elif len(potential_rogue_missions) > 0:
        min_dist_alloc = bot_utils.get_minimal_distance_allocation(
            my_unassigned_ships, potential_rogue_missions)
        rogue_ship = bot_utils.get_shortest_alloc(min_dist_alloc)
        orders[rogue_ship] = min_dist_alloc[rogue_ship]
        my_unassigned_ships.remove(rogue_ship)
        rogue_missions_id[rogue_ship.id] = min_dist_alloc[rogue_ship]
    if len(rogue_missions_id) > 0:
        logging.info(
            f'rogue_missions: {dict([(ship_id, planet.id) for ship_id, planet in rogue_missions_id.items()])}'
        )

    # handle distractions (maybe move after rogue missions)
    distraction_alloc = \
        bot_utils.get_minimal_distance_allocation(my_unassigned_ships,
                                                  potential_distraction_planets * max_distraction_response)
    for ship in distraction_alloc:
        orders[ship] = distraction_alloc[ship]