pub fn new(roles: Vec<Role>, num_players: usize) -> Multiverse {
        let mut permutations = vec![vec![Role::Villager; num_players]];
        for role in roles {
            permutations = permutations.into_iter().flat_map(|perm| {
                (0..perm.len()).filter_map(|i| {
                    if perm[i] == Role::Villager {
                        let mut new_perm = perm.clone();
                        new_perm[i] = role;
                        Some(new_perm)
                    } else {
                        None
                    }
                }).collect::<Vec<_>>()
            }).collect();
        }
        Multiverse(permutations.into_iter().map(Universe::from).collect())
    }
/// Constructs and returns a new multiverse with all possible role distributions.
///
/// If fewer roles than players are given, the remaining role slots will be populated with villagers.
Constructs and returns a new multiverse with all possible role distributions.
If fewer roles than players are given, the remaining role slots will be populated with villagers.
Constructs and returns a new multiverse with all possible role distributions . If fewer roles than players are given the remaining role slots will be populated with villagers .
pub fn new(roles: Vec<Role>, num_players: usize) -> Multiverse {
        let mut permutations = vec![vec![Role::Villager; num_players]];
        for role in roles {
            permutations = permutations.into_iter().flat_map(|perm| {
                (0..perm.len()).filter_map(|i| {
                    if perm[i] == Role::Villager {
                        let mut new_perm = perm.clone();
                        new_perm[i] = role;
                        Some(new_perm)
                    } else {
                        None
                    }
                }).collect::<Vec<_>>()
            }).collect();
        }
        Multiverse(permutations.into_iter().map(Universe::from).collect())
    }
pub fn new ( roles : Vec < Role > , num_players : usize ) -> Multiverse { let mut permutations = vec ! [ vec [ Role Villager num_players ] ] ; for role in roles { permutations = permutations . into_iter ( ) . flat_map ( | perm | { ( 0 .. perm . len ( ) ) . filter_map ( | i | { if perm [ i ] == Role :: Villager { let mut new_perm = perm . clone ( ) ; new_perm [ i ] = role ; Some ( new_perm ) } else { None } } ) . collect :: < Vec < _ > > ( ) } ) . collect ( ) ; } Multiverse ( permutations . into_iter ( ) . map ( Universe :: from ) . collect ( ) ) }
Constructs and returns a new multiverse with all possible role distributions.
Constructs and returns a new multiverse with all possible role distributions .
roles
Vec<Role>
num_players
usize
roles
Vec<Role>
num_players
usize