pub fn shortest_path_roomxy_single_goal<G>(
start: RoomXY,
goal: RoomXY,
cost_fn: G,
) -> AStarSearchResults<RoomXY, u32>Expand description
Convenience function for the common use-case of searching from a single starting node to a single goal node.
Uses sane default values for maximum operations and travel costs. For more fine-grained control, see: shortest_path_generic_grid
ยงExample
use screeps::{LocalRoomTerrain, RoomXY};
let start = RoomXY::checked_new(24, 18).unwrap();
let goal = RoomXY::checked_new(34, 40).unwrap();
let room_terrain = LocalRoomTerrain::new_from_bits(Box::new([0; 2500])); // Terrain that's all plains
let plain_cost = 1;
let swamp_cost = 5;
let costs = screeps_pathfinding::utils::movement_costs::get_movement_cost_lcm_from_terrain(&room_terrain, plain_cost, swamp_cost);
let costs_fn = screeps_pathfinding::utils::movement_costs::astar_movement_costs_from_lcm(&costs);
let search_results = screeps_pathfinding::algorithms::astar::shortest_path_roomxy_single_goal(
start,
goal,
costs_fn,
);
if !search_results.incomplete() {
let path = search_results.path();
println!("Path: {:?}", path);
}
else {
println!("Could not find A* shortest path.");
println!("Search Results: {:?}", search_results);
}