pub fn random_rune_page() -> Result<(PrimaryTree, SecondaryTree), Error> {
    let runes: RuneList = serde_json::from_str(&open_file("runes")?)?;
    let mut rng = rand::thread_rng();

    let path_names = ["Precision", "Domination", "Sorcery", "Resolve", "Inspiration"];
    let path_arr = [runes.precision, runes.domination,
                    runes.sorcery, runes.resolve, runes.inspiration];

    // Get the rune paths
    let r = Range::new(0, 5);
    let primary_ix = r.ind_sample(&mut rng);
    let secondary_ix = {
        let mut t = r.ind_sample(&mut rng);
        while t == primary_ix {
            t = r.ind_sample(&mut rng);
        }
        t
    };

    let primary_path = &path_arr[primary_ix];
    let secondary_path = &path_arr[secondary_ix];

    // Determine the secondary rune path tiers
    let r = Range::new(1, 4);
    let sec_ai = r.ind_sample(&mut rng);
    let sec_bi = {
        let mut t = r.ind_sample(&mut rng);
        while t == sec_ai {
            t = r.ind_sample(&mut rng);
        }
        t
    };

    macro_rules! tier {
        ($ix:ident) => (match $ix {
            1 => &secondary_path.tier1,
            2 => &secondary_path.tier2,
            3 => &secondary_path.tier3,
            _ => &secondary_path.tier1,
        })
    }

    let sec_a = tier!(sec_ai);
    let sec_b = tier!(sec_bi);

    // Finalise
    Ok((
        PrimaryTree {
            name: path_names[primary_ix].to_string(),
            keystone: rng.choose(&primary_path.keystone).ok_or(failure::err_msg("Empty keystone?"))?.to_string(),
            tier1: rng.choose(&primary_path.tier1).ok_or(failure::err_msg("Empty tier1?"))?.to_string(),
            tier2: rng.choose(&primary_path.tier2).ok_or(failure::err_msg("Empty tier2?"))?.to_string(),
            tier3: rng.choose(&primary_path.tier3).ok_or(failure::err_msg("Empty tier3?"))?.to_string(),
        },
        SecondaryTree {
            name: path_names[secondary_ix].to_string(),
            runes: (
                rng.choose(sec_a).ok_or(failure::err_msg("Empty secondary?"))?.to_string(),
                rng.choose(sec_b).ok_or(failure::err_msg("Empty secondary?"))?.to_string(),
            )
        },
    ))
}
/// Returns a primary and secondary rune tree.
Returns a primary and secondary rune tree.
Returns a primary and secondary rune tree .
pub fn random_rune_page() -> Result<(PrimaryTree, SecondaryTree), Error> {
    let runes: RuneList = serde_json::from_str(&open_file("runes")?)?;
    let mut rng = rand::thread_rng();
    let path_names = ["Precision", "Domination", "Sorcery", "Resolve", "Inspiration"];
    let path_arr = [runes.precision, runes.domination,
                    runes.sorcery, runes.resolve, runes.inspiration];
    // Get the rune paths
    let r = Range::new(0, 5);
    let primary_ix = r.ind_sample(&mut rng);
    let secondary_ix = {
        let mut t = r.ind_sample(&mut rng);
        while t == primary_ix {
            t = r.ind_sample(&mut rng);
        }
        t
    };
    let primary_path = &path_arr[primary_ix];
    let secondary_path = &path_arr[secondary_ix];
    // Determine the secondary rune path tiers
    let r = Range::new(1, 4);
    let sec_ai = r.ind_sample(&mut rng);
    let sec_bi = {
        let mut t = r.ind_sample(&mut rng);
        while t == sec_ai {
            t = r.ind_sample(&mut rng);
        }
        t
    };
    macro_rules! tier {
        ($ix:ident) => (match $ix {
            1 => &secondary_path.tier1,
            2 => &secondary_path.tier2,
            3 => &secondary_path.tier3,
            _ => &secondary_path.tier1,
        })
    }
    let sec_a = tier!(sec_ai);
    let sec_b = tier!(sec_bi);
    // Finalise
    Ok((
        PrimaryTree {
            name: path_names[primary_ix].to_string(),
            keystone: rng.choose(&primary_path.keystone).ok_or(failure::err_msg("Empty keystone?"))?.to_string(),
            tier1: rng.choose(&primary_path.tier1).ok_or(failure::err_msg("Empty tier1?"))?.to_string(),
            tier2: rng.choose(&primary_path.tier2).ok_or(failure::err_msg("Empty tier2?"))?.to_string(),
            tier3: rng.choose(&primary_path.tier3).ok_or(failure::err_msg("Empty tier3?"))?.to_string(),
        },
        SecondaryTree {
            name: path_names[secondary_ix].to_string(),
            runes: (
                rng.choose(sec_a).ok_or(failure::err_msg("Empty secondary?"))?.to_string(),
                rng.choose(sec_b).ok_or(failure::err_msg("Empty secondary?"))?.to_string(),
            )
        },
    ))
}
pub fn random_rune_page ( ) -> Result < ( PrimaryTree , SecondaryTree ) , Error > { let runes : RuneList = serde_json :: from_str ( & open_file ( " " ) ? ) ? ; let mut rng = rand :: thread_rng ( ) ; let path_names = [ " " , " " , " " , " " , " " ] ; let path_arr = [ runes . precision , runes . domination , runes . sorcery , runes . resolve , runes . inspiration ] ; // Get the rune paths let r = Range :: new ( 0 , 5 ) ; let primary_ix = r . ind_sample ( & mut rng ) ; let secondary_ix = { let mut t = r . ind_sample ( & mut rng ) ; while t == primary_ix { t = r . ind_sample ( & mut rng ) ; } t } ; let primary_path = & path_arr [ primary_ix ] ; let secondary_path = & path_arr [ secondary_ix ] ; // Determine the secondary rune path tiers let r = Range :: new ( 1 , 4 ) ; let sec_ai = r . ind_sample ( & mut rng ) ; let sec_bi = { let mut t = r . ind_sample ( & mut rng ) ; while t == sec_ai { t = r . ind_sample ( & mut rng ) ; } t } ; macro_rules! tier { ( $ix : ident ) => ( match $ix { 1 secondary_path tier1 2 secondary_path tier2 3 secondary_path tier3 secondary_path tier1 } ) } let sec_a = tier ! ( sec_ai ) ; let sec_b = tier ! ( sec_bi ) ; // Finalise Ok ( ( PrimaryTree { name : path_names [ primary_ix ] . to_string ( ) , keystone : rng . choose ( & primary_path . keystone ) . ok_or ( failure :: err_msg ( " " ) ) ? . to_string ( ) , tier1 : rng . choose ( & primary_path . tier1 ) . ok_or ( failure :: err_msg ( " " ) ) ? . to_string ( ) , tier2 : rng . choose ( & primary_path . tier2 ) . ok_or ( failure :: err_msg ( " " ) ) ? . to_string ( ) , tier3 : rng . choose ( & primary_path . tier3 ) . ok_or ( failure :: err_msg ( " " ) ) ? . to_string ( ) , } , SecondaryTree { name : path_names [ secondary_ix ] . to_string ( ) , runes : ( rng . choose ( sec_a ) . ok_or ( failure :: err_msg ( " " ) ) ? . to_string ( ) , rng . choose ( sec_b ) . ok_or ( failure :: err_msg ( " " ) ) ? . to_string ( ) , ) } , ) ) }
Returns a primary and secondary rune tree.
Returns a primary and secondary rune tree .