コード例 #1
0
def hunt(unit, gc, enem, earth_map):
    enemy, dist = utilities.nearest_unit(unit, enem, gc, [])
    loc = unit.location.map_location()
    if not enemy == loc:
        if not unit.id in ranger_paths or not enemy == ranger_paths[
                unit.id][-1]:
            ranger_paths[unit.id] = utilities.find_path(
                loc, enemy, earth_map, gc)
        if utilities.move(
                unit, gc,
                utilities.loc_to_direction(enemy, ranger_paths[unit.id][1])):
            if len(ranger_paths[unit.id]) < 2:
                ranger_paths.__delitem__(unit.id)
            else:
                (ranger_paths[unit.id]).__delitem__(1)
            return True
    return False
コード例 #2
0
def find_karbonite(unit, gc, earth_map, mars_map, initialkarbonite):
    loc = unit.location
    if loc.is_on_planet(bc.Planet.Earth):
        karb, dist = utilities.nearest_karbonite(unit, initialkarbonite, gc)
        if not unit.id in worker_paths or not karb == worker_paths[
                unit.id][-1]:
            worker_paths[unit.id] = utilities.find_path(
                loc.map_location(), karb, earth_map, gc)
        if utilities.move(
                unit, gc,
                utilities.loc_to_direction(loc.map_location(),
                                           worker_paths[unit.id][1])):
            if len(worker_paths[unit.id]) < 2:
                worker_paths.__delitem__(unit.id)
            else:
                (worker_paths[unit.id]).__delitem__(1)
            return True
    return False