//
// Created by Dan Crosby on 8/31/23.
//

#include "AIMinimumDistanceAndTarget.hpp"

namespace shardok {
auto MinimumDistanceAndTarget(
        const ActionPointDistances *apd,
        const Coords &origin,
        const CoordsSet &destinations) -> CoordsAndDistance {
    CoordsAndDistance min{Coords(-1, -1), ActionPointDistances::IMPOSSIBLE};
    for (const auto &dest : destinations) {
        const DIST_T dist = apd->Distance(origin, dest);
        if (dist == ActionPointDistances::IMPOSSIBLE) continue;
        if (dist < min.distance) min = CoordsAndDistance{dest, dist};
    }

    return min;
}

auto MinimumDistance(
        const ActionPointDistances *apd,
        const Coords &origin,
        const CoordsSet &destinations) -> int {
    return MinimumDistanceAndTarget(apd, origin, destinations).distance;
}
}  // namespace shardok