remove unwraps in npc_ai

This commit is contained in:
Isse 2023-04-13 22:41:39 +02:00
parent d1f6e6bef6
commit 2b44d534cb

View File

@ -137,23 +137,21 @@ fn path_between_sites(
let neighbors = |site: &Id<civ::Site>| world.civs().neighbors(*site); let neighbors = |site: &Id<civ::Site>| world.civs().neighbors(*site);
let track_between = |a: Id<civ::Site>, b: Id<civ::Site>| { let transition = |a: &Id<civ::Site>, b: &Id<civ::Site>| {
world world.civs().track_between(*a, *b).map(|(id, _)| {
.civs() world.civs().tracks.get(id).cost
.tracks }).unwrap_or(f32::INFINITY)
.get(world.civs().track_between(a, b).unwrap().0)
}; };
let transition = |a: &Id<civ::Site>, b: &Id<civ::Site>| track_between(*a, *b).cost;
let path = astar.poll(250, heuristic, neighbors, transition, |site| *site == end); let path = astar.poll(250, heuristic, neighbors, transition, |site| *site == end);
path.map(|path| { path.map(|path| {
let path = path let path = path
.into_iter() .into_iter()
.tuple_windows::<(_, _)>() .tuple_windows::<(_, _)>()
.map(|(a, b)| world.civs().track_between(a, b).unwrap()) // Since we get a, b from neighbors, track_between shouldn't return None.
.collect_vec(); .filter_map(|(a, b)| world.civs().track_between(a, b))
.collect();
Path { nodes: path } Path { nodes: path }
}) })
} }