Ejemplo n.º 1
0
def score_planet(pw: planet_wars.PlanetWars, p: planet_wars.Planet):
    """
    Function to give a planet a score based on many factors.
    :param pw: `PlanetWars` object
    :param p: `Planet` object
    :return: `float` score of planet
    """

    raw_score = get_raw_score(p)

    structural_score = 1 - (pythag(MY_PLANETS_CENTER,
                                   (p.x(), p.y())) / pw.map_size)

    surrounding_score = 0
    for planet in filter(lambda _p: _p != p, pw.planets()):
        temp = (
            1 -
            (pw.distance(p.planet_id(), planet.planet_id()) / pw.map_size))**5
        surrounding_score += get_raw_score(planet) * temp
    surrounding_score /= pw.total_growth

    latency_score = p.latency / pw.map_size

    center_score = 1 - (pw.distance(p.planet_id(), 0) / pw.map_size)

    score = 0
    score += raw_score
    score += STRUCTURAL_FACTOR * structural_score
    score += SURROUNDING_FACTOR * surrounding_score
    score += LATENCY_FACTOR * latency_score
    score += CENTER_FACTOR * center_score

    return score
Ejemplo n.º 2
0
def furthest_meaningful_planet(pw: planet_wars.PlanetWars,
                               planet: planet_wars.Planet, owner: int):
    planets = tuple(filter(lambda p: p.owner() == owner, pw.planets()))
    fleets = tuple(filter(lambda f: f.owner() == owner, pw.fleets()))

    furthest_distance = 0
    for other_planet in planets:
        furthest_distance = max(
            furthest_distance,
            pw.distance(other_planet.planet_id(), planet.planet_id()))
    for fleet in fleets:
        furthest_distance = max(
            furthest_distance,
            fleet.turns_remaining() +
            pw.distance(fleet.destination_planet(), planet.planet_id()))

    return furthest_distance
Ejemplo n.º 3
0
def turn_to_take(pw: planet_wars.PlanetWars, my_planet: planet_wars.Planet,
                 neutral_planet: planet_wars.Planet):
    """
    Finds the minimum turns to take `neutral_planet` with `my_planet`.
    :param pw: `PlanetWars` object
    :param my_planet: `Planet` object
    :param neutral_planet: `Planet` object
    :return: `int` turns to take the planet
    """

    distance = pw.distance(my_planet.planet_id(), neutral_planet.planet_id())
    if my_planet.num_ships() > neutral_planet.num_ships():
        return distance
    else:
        lacking_ships = neutral_planet.num_ships() - my_planet.num_ships() + 1
        for t in range(pw.map_size):
            lacking_ships -= my_planet.my_arriving_ships[
                t] + my_planet.growth_rate()
            if lacking_ships <= 0:
                break
        else:
            return 999999
        return distance + t