Exemple #1
0
def go_to_mars_sense(gc, unit, battle_locs, location, enemies,
                     direction_to_coord, bfs_array, targeting_units,
                     rocket_locs):
    # print('GOING TO MARS')
    signals = {}
    dir = None
    attack = None
    blink = None
    closest_enemy = None
    move_then_attack = False
    visible_enemies = False

    if len(enemies) > 0:
        visible_enemies = True
        attack = Ranger.get_attack(gc, unit, location, targeting_units)
    start_coords = (location.x, location.y)

    # # rocket was launched
    if unit.id not in variables.which_rocket or variables.which_rocket[
            unit.id][1] not in variables.rocket_locs:
        variables.mage_roles["go_to_mars"].remove(unit.id)
        return dir, attack, blink, move_then_attack, visible_enemies, closest_enemy, signals
    target_loc = variables.which_rocket[unit.id][0]

    # # rocket was destroyed
    if not gc.has_unit_at_location(target_loc):
        variables.mage_roles["go_to_mars"].remove(unit.id)
        return dir, attack, blink, move_then_attack, visible_enemies, closest_enemy, signals
    # print(unit.id)
    # print('MY LOCATION:', start_coords)
    # print('GOING TO:', target_loc)
    if max(abs(target_loc.x - start_coords[0]),
           abs(target_loc.y - start_coords[1])) == 1:
        rocket = gc.sense_unit_at_location(target_loc)
        if gc.can_load(rocket.id, unit.id):
            gc.load(rocket.id, unit.id)
    else:
        target_coords = (target_loc.x, target_loc.y)
        start_coords_val = Ranger.get_coord_value(start_coords)
        target_coords_val = Ranger.get_coord_value(target_coords)
        # target_coords_thirds = (int(target_loc.x / bfs_fineness), int(target_loc.y / bfs_fineness))

        if bfs_array[start_coords_val, target_coords_val] != float('inf'):
            best_dirs = Ranger.use_dist_bfs(start_coords, target_coords,
                                            bfs_array)
            choice_of_dir = random.choice(best_dirs)
            shape = direction_to_coord[choice_of_dir]
            options = sense_util.get_best_option(shape)
            for option in options:
                if gc.can_move(unit.id, option):
                    dir = option
                    break
                    # print(dir)

    return dir, attack, blink, move_then_attack, visible_enemies, closest_enemy, signals
Exemple #2
0
def try_move_smartly(unit, map_loc1, map_loc2):
    if variables.gc.is_move_ready(unit.id):
        our_coords = map_loc1
        target_coords = map_loc2
        bfs_array = variables.bfs_array
        our_coords_val = Ranger.get_coord_value(our_coords)
        target_coords_val = Ranger.get_coord_value(target_coords)
        if bfs_array[our_coords_val, target_coords_val]!=float('inf'):
            best_dirs = Ranger.use_dist_bfs(our_coords, target_coords, bfs_array)
            choice_of_dir = random.choice(best_dirs)
            shape = variables.direction_to_coord[choice_of_dir]
            options = sense_util.get_best_option(shape)
            for option in options:
                if variables.gc.can_move(unit.id, option):
                    variables.gc.move_robot(unit.id, option)
                    add_new_location(unit.id, our_coords, option)
                    break