heuristic_get_range_to_multigoal

Function heuristic_get_range_to_multigoal 

Source
pub fn heuristic_get_range_to_multigoal<T: GetRangeTo + Copy>(
    goals: &[T],
) -> impl Fn(T) -> u32 + '_
Expand description

Helper function to create a heuristic cost function closure for multiple goal nodes.

This heuristic cost is simply the minimum range between the provided node and each of the goal nodes.

If using the convenience functions for common pathfinding use-cases, you will not normally need to use this function.

ยงExamples

use screeps::RoomXY;
use screeps_pathfinding::utils::goals::goal_exact_node_multigoal;
use screeps_pathfinding::utils::heuristics::heuristic_get_range_to_multigoal;

let start = RoomXY::checked_new(24, 18).unwrap();
let goal_a = RoomXY::checked_new(34, 40).unwrap();
let goal_b = RoomXY::checked_new(34, 45).unwrap();
let goals = &[goal_a, goal_b];
let cost_fn = |_| Some(1);
screeps_pathfinding::algorithms::astar::shortest_path_roomxy(
    start,
    &goal_exact_node_multigoal(goals),
    cost_fn,
    &heuristic_get_range_to_multigoal(goals),
);