Skip to main content

steer

Function steer 

Source
pub fn steer(
    path: &[Pos],
    to: Pos,
    cheapest: impl FnOnce(Pos) -> Option<Vec<Pos>>,
    valid: impl Fn(&[Pos]) -> bool,
) -> Vec<Pos>
Expand description

The path after the cursor moves to to. path runs from the unit’s tile (never empty); valid says whether a path is legal (the game’s rules: the unit’s move points, who stands where), and cheapest gives the cheapest path to a tile, or None if the unit can’t reach it (shuyi_core::Reach::path_to).

  • to already on the path: the path is cut back to it.
  • to next to the path’s end and the longer path is legal: to is appended, so the player can steer a route.
  • Otherwise the cheapest path to to, or the path unchanged if to can’t be reached.