//Not the most elegant approach to handcraft this thing ^^
Not the most elegant approach to handcraft this thing ^^
Not the most elegant approach to handcraft this thing ^^
fn build_transitions() -> Transitions {
    use Node::*;
    //All possible transition functions in the grid
    //The type inference is horrendous here so we have to help hard!
    //TODO: Search for bad error message 
    //https://play.rust-lang.org/?gist=8fc3d35987f091f3876ca8056e03a4b0&version=stable
    let min9: RcType = Rc::new((|x| x - 9, " - 9".to_owned()));
    let min4: RcType = Rc::new((|x| x - 4, " - 4".to_owned()));
    let plus4: RcType = Rc::new((|x| x + 4, " + 4".to_owned()));
    let min18: RcType = Rc::new((|x| x - 18, " - 18".to_owned()));
    let min1: RcType = Rc::new((|x| x - 1, " - 1".to_owned()));
    let min11: RcType = Rc::new((|x| x - 11, " - 11".to_owned()));
    let min8: RcType = Rc::new((|x| x - 8, " - 8".to_owned()));
    let tim4: RcType = Rc::new((|x| x * 4, " * 4".to_owned()));
    let tim18: RcType = Rc::new((|x| x * 18, " * 18".to_owned()));
    let tim11: RcType = Rc::new((|x| x * 11, " * 11".to_owned()));
    let tim8: RcType = Rc::new((|x| x * 8, " * 8".to_owned()));
    let tim9: RcType = Rc::new((|x| x * 9, " * 9".to_owned()));
    let id: RcType = Rc::new((|x| x, " * 1".to_owned()));
    let mut res = HashMap::new();
    //transitions from start
    let start = vec![
        (Bottom9, Rc::clone(&min9)),
        (Middle4, Rc::clone(&min4)),
        (Middle4, Rc::clone(&plus4)),
        (Left4, Rc::clone(&plus4)),
    ];
    res.insert(Start, start);
    //transitions from 9
    let bnine = vec![
        (Middle4, Rc::clone(&min4)),
        (Bottom9, Rc::clone(&min9)),
        (Bottom9, Rc::clone(&tim9)),
        (Right18, Rc::clone(&tim18)),
        (Right18, Rc::clone(&min18)),
        (Middle11, Rc::clone(&min11)),
    ];
    res.insert(Bottom9, bnine);
    //Transitions from middle 4
    let mfour = vec![
        (Middle4, Rc::clone(&min4)),
        (Middle4, Rc::clone(&plus4)),
        (Middle4, Rc::clone(&tim4)),
        (Bottom9, Rc::clone(&min9)),
        (Middle11, Rc::clone(&tim11)),
        (Middle11, Rc::clone(&min11)),
        (Left4, Rc::clone(&tim4)),
        (Left4, Rc::clone(&plus4)),
        (Right18, Rc::clone(&min18)),
        (Top8, Rc::clone(&tim8)),
    ];
    res.insert(Middle4, mfour);
    //Transitions from left 4
    let lfour = vec![
        (Left4, Rc::clone(&plus4)),
        (Left4, Rc::clone(&tim4)),
        (Top8, Rc::clone(&tim8)),
        (Middle11, Rc::clone(&tim11)),
        (Middle4, Rc::clone(&plus4)),
        (Middle4, Rc::clone(&tim4)),
    ];
    res.insert(Left4, lfour);
    //All the transitions from the right 18
    let reightteen = vec![
        (Right18, Rc::clone(&tim18)),
        (Right18, Rc::clone(&min18)),
        (Middle11, Rc::clone(&min11)),
        (Middle11, Rc::clone(&tim11)),
        (Bottom9, Rc::clone(&min9)),
        (Bottom9, Rc::clone(&tim9)),
        (Middle4, Rc::clone(&min4)),
        (Door, Rc::clone(&id)),
    ];
    res.insert(Right18, reightteen);
    //All transitions from the middle 11
    let meleven = vec![
        (Middle11, Rc::clone(&min11)),
        (Middle11, Rc::clone(&tim11)),
        (Right18, Rc::clone(&min18)),
        (Right18, Rc::clone(&tim18)),
        (Bottom9, Rc::clone(&min9)),
        (Middle4, Rc::clone(&min4)),
        (Middle4, Rc::clone(&tim4)),
        (Left4, Rc::clone(&tim4)),
        (Top8, Rc::clone(&tim8)),
        (Top8, Rc::clone(&min8)),
        (Door, Rc::clone(&id)),
        (Door, Rc::clone(&min1)),
    ];
    res.insert(Middle11, meleven);
    //All transitions from top 8
    let teight = vec![
        (Top8, Rc::clone(&min8)),
        (Top8, Rc::clone(&tim8)),
        (Left4, Rc::clone(&tim4)),
        (Middle4, Rc::clone(&tim4)),
        (Middle11, Rc::clone(&min11)),
        (Middle11, Rc::clone(&tim11)),
        (Door, Rc::clone(&min1)),
    ];
    res.insert(Top8, teight);
    res
}
fn build_transitions ( ) -> Transitions { use Node :: * ; //All possible transition functions in the grid //The type inference is horrendous here so we have to help hard! //TODO: Search for bad error message  //https://play.rust-lang.org/?gist=8fc3d35987f091f3876ca8056e03a4b0&version=stable let min9 : RcType = Rc :: new ( ( | x | x - 9 , " " . to_owned ( ) ) ) ; let min4 : RcType = Rc :: new ( ( | x | x - 4 , " " . to_owned ( ) ) ) ; let plus4 : RcType = Rc :: new ( ( | x | x + 4 , " " . to_owned ( ) ) ) ; let min18 : RcType = Rc :: new ( ( | x | x - 18 , " " . to_owned ( ) ) ) ; let min1 : RcType = Rc :: new ( ( | x | x - 1 , " " . to_owned ( ) ) ) ; let min11 : RcType = Rc :: new ( ( | x | x - 11 , " " . to_owned ( ) ) ) ; let min8 : RcType = Rc :: new ( ( | x | x - 8 , " " . to_owned ( ) ) ) ; let tim4 : RcType = Rc :: new ( ( | x | x * 4 , " " . to_owned ( ) ) ) ; let tim18 : RcType = Rc :: new ( ( | x | x * 18 , " " . to_owned ( ) ) ) ; let tim11 : RcType = Rc :: new ( ( | x | x * 11 , " " . to_owned ( ) ) ) ; let tim8 : RcType = Rc :: new ( ( | x | x * 8 , " " . to_owned ( ) ) ) ; let tim9 : RcType = Rc :: new ( ( | x | x * 9 , " " . to_owned ( ) ) ) ; let id : RcType = Rc :: new ( ( | x | x , " " . to_owned ( ) ) ) ; let mut res = HashMap :: new ( ) ; //transitions from start let start = vec ! [ ( Bottom9 Rc clone ( min9 ) ) ( Middle4 Rc clone ( min4 ) ) ( Middle4 Rc clone ( plus4 ) ) ( Left4 Rc clone ( plus4 ) ) ] ; res . insert ( Start , start ) ; //transitions from 9 let bnine = vec ! [ ( Middle4 Rc clone ( min4 ) ) ( Bottom9 Rc clone ( min9 ) ) ( Bottom9 Rc clone ( tim9 ) ) ( Right18 Rc clone ( tim18 ) ) ( Right18 Rc clone ( min18 ) ) ( Middle11 Rc clone ( min11 ) ) ] ; res . insert ( Bottom9 , bnine ) ; //Transitions from middle 4 let mfour = vec ! [ ( Middle4 Rc clone ( min4 ) ) ( Middle4 Rc clone ( plus4 ) ) ( Middle4 Rc clone ( tim4 ) ) ( Bottom9 Rc clone ( min9 ) ) ( Middle11 Rc clone ( tim11 ) ) ( Middle11 Rc clone ( min11 ) ) ( Left4 Rc clone ( tim4 ) ) ( Left4 Rc clone ( plus4 ) ) ( Right18 Rc clone ( min18 ) ) ( Top8 Rc clone ( tim8 ) ) ] ; res . insert ( Middle4 , mfour ) ; //Transitions from left 4 let lfour = vec ! [ ( Left4 Rc clone ( plus4 ) ) ( Left4 Rc clone ( tim4 ) ) ( Top8 Rc clone ( tim8 ) ) ( Middle11 Rc clone ( tim11 ) ) ( Middle4 Rc clone ( plus4 ) ) ( Middle4 Rc clone ( tim4 ) ) ] ; res . insert ( Left4 , lfour ) ; //All the transitions from the right 18 let reightteen = vec ! [ ( Right18 Rc clone ( tim18 ) ) ( Right18 Rc clone ( min18 ) ) ( Middle11 Rc clone ( min11 ) ) ( Middle11 Rc clone ( tim11 ) ) ( Bottom9 Rc clone ( min9 ) ) ( Bottom9 Rc clone ( tim9 ) ) ( Middle4 Rc clone ( min4 ) ) ( Door Rc clone ( id ) ) ] ; res . insert ( Right18 , reightteen ) ; //All transitions from the middle 11 let meleven = vec ! [ ( Middle11 Rc clone ( min11 ) ) ( Middle11 Rc clone ( tim11 ) ) ( Right18 Rc clone ( min18 ) ) ( Right18 Rc clone ( tim18 ) ) ( Bottom9 Rc clone ( min9 ) ) ( Middle4 Rc clone ( min4 ) ) ( Middle4 Rc clone ( tim4 ) ) ( Left4 Rc clone ( tim4 ) ) ( Top8 Rc clone ( tim8 ) ) ( Top8 Rc clone ( min8 ) ) ( Door Rc clone ( id ) ) ( Door Rc clone ( min1 ) ) ] ; res . insert ( Middle11 , meleven ) ; //All transitions from top 8 let teight = vec ! [ ( Top8 Rc clone ( min8 ) ) ( Top8 Rc clone ( tim8 ) ) ( Left4 Rc clone ( tim4 ) ) ( Middle4 Rc clone ( tim4 ) ) ( Middle11 Rc clone ( min11 ) ) ( Middle11 Rc clone ( tim11 ) ) ( Door Rc clone ( min1 ) ) ] ; res . insert ( Top8 , teight ) ; res }
Not the most elegant approach to handcraft this thing ^^
Not the most elegant approach to handcraft this thing ^^