use std::vec::IntoIter;
use rusty_planner::any_dyn_astar;
use rusty_planner::planner;
struct Robots {
start: (i32, i32),
goal: (i32, i32),
}
impl planner::ProblemSpace for Robots {
type State = (i32, i32);
type Iter = IntoIter<((i32, i32), f64)>;
fn heuristic(&self, p: &Self::State, q: &Self::State) -> f64 {
((q.0 - p.0).pow(2) as f64 + (q.1 - p.1).pow(2) as f64).sqrt()
}
fn succ(&self, state: &Self::State) -> Self::Iter {
let mut v = vec![];
let (x, y) = *state;
if x < 10 && y < 10 && x == y {
v.push(((x + 1, y + 1), 1.0));
}
if x < 10 && y == 0 {
v.push(((x + 1, y), 0.5));
} else if x == 10 && y < 10 {
v.push(((x, y + 1), 0.8));
}
v.into_iter()
}
fn pred(&self, state: &Self::State) -> Self::Iter {
let mut v = vec![];
let (x, y) = *state;
if x > 0 && y > 0 && x == y {
v.push(((x - 1, y - 1), 1.0));
}
if x > 0 && y == 0 {
v.push(((x - 1, y), 0.5));
} else if x == 10 && y > 0 {
v.push(((x, y - 1), 0.8));
}
v.into_iter()
}
}
fn callback(path: Vec<(i32, i32)>) {
for x in &path {
println!("Robot @ ({}, {})", x.0, x.1);
}
}
fn main() {
let robots = Robots {
start: (0, 0),
goal: (10, 10),
};
any_dyn_astar::solve(&robots, robots.start, robots.goal, callback);
}