pub fn start(self, roles: Vec<Role>) -> Result<State<P>, StartGameError> {
        let num_players = self.num_players();
        if num_players < MIN_PLAYERS {
            return Err(StartGameError::NotEnoughPlayers { required: MIN_PLAYERS, found: num_players });
        }
        if num_players < roles.len() {
            return Err(StartGameError::RolesCount { required: num_players, found: roles.len() });
        }
        let Signups { player_names } = self;
        let mut secret_ids = player_names.into_iter().collect::<Vec<_>>();
        secret_ids.shuffle(&mut thread_rng());
        let roles = roles.into_iter()
            .filter(|&role| role != Role::Villager)
            .fold((0, Vec::default()), |(mut num_ww, mut roles), role| {
                if let Role::Werewolf(_) = role {
                    roles.push(Role::Werewolf(num_ww));
                    num_ww += 1;
                } else {
                    roles.push(role);
                }
                (num_ww, roles)
            }).1;
        let multiverse = Multiverse::new(roles, num_players);
        // check for game-ending conditions
        if multiverse.game_over(false) {
            return Ok(State::Complete(Complete::new(secret_ids, multiverse)));
        }
        Ok(State::Night(Night {
            secret_ids, multiverse,
            last_heals: vec![None; num_players]
        }))
    }
/// Start the game.
///
/// If fewer roles than players are given, a number of Villagers equal to the difference will be added.
Start the game.
If fewer roles than players are given, a number of Villagers equal to the difference will be added.
Start the game . If fewer roles than players are given a number of Villagers equal to the difference will be added .
pub fn start(self, roles: Vec<Role>) -> Result<State<P>, StartGameError> {
        let num_players = self.num_players();
        if num_players < MIN_PLAYERS {
            return Err(StartGameError::NotEnoughPlayers { required: MIN_PLAYERS, found: num_players });
        }
        if num_players < roles.len() {
            return Err(StartGameError::RolesCount { required: num_players, found: roles.len() });
        }
        let Signups { player_names } = self;
        let mut secret_ids = player_names.into_iter().collect::<Vec<_>>();
        secret_ids.shuffle(&mut thread_rng());
        let roles = roles.into_iter()
            .filter(|&role| role != Role::Villager)
            .fold((0, Vec::default()), |(mut num_ww, mut roles), role| {
                if let Role::Werewolf(_) = role {
                    roles.push(Role::Werewolf(num_ww));
                    num_ww += 1;
                } else {
                    roles.push(role);
                }
                (num_ww, roles)
            }).1;
        let multiverse = Multiverse::new(roles, num_players);
        // check for game-ending conditions
        if multiverse.game_over(false) {
            return Ok(State::Complete(Complete::new(secret_ids, multiverse)));
        }
        Ok(State::Night(Night {
            secret_ids, multiverse,
            last_heals: vec![None; num_players]
        }))
    }
pub fn start ( self , roles : Vec < Role > ) -> Result < State < P > , StartGameError > { let num_players = self . num_players ( ) ; if num_players < MIN_PLAYERS { return Err ( StartGameError :: NotEnoughPlayers { required : MIN_PLAYERS , found : num_players } ) ; } if num_players < roles . len ( ) { return Err ( StartGameError :: RolesCount { required : num_players , found : roles . len ( ) } ) ; } let Signups { player_names } = self ; let mut secret_ids = player_names . into_iter ( ) . collect :: < Vec < _ > > ( ) ; secret_ids . shuffle ( & mut thread_rng ( ) ) ; let roles = roles . into_iter ( ) . filter ( | & role | role != Role :: Villager ) . fold ( ( 0 , Vec :: default ( ) ) , | ( mut num_ww , mut roles ) , role | { if let Role :: Werewolf ( _ ) = role { roles . push ( Role :: Werewolf ( num_ww ) ) ; num_ww += 1 ; } else { roles . push ( role ) ; } ( num_ww , roles ) } ) . 1 ; let multiverse = Multiverse :: new ( roles , num_players ) ; // check for game-ending conditions if multiverse . game_over ( false ) { return Ok ( State :: Complete ( Complete :: new ( secret_ids , multiverse ) ) ) ; } Ok ( State :: Night ( Night { secret_ids , multiverse , last_heals : vec ! [ None num_players ] } ) ) }
Start the game.
Start the game .
self
roles
Vec<Role>
self
roles
Vec<Role>