fn sanitized_night_actions(&self, night_actions: &[NightAction<P>]) -> Vec<NightAction<usize>> {
        let mut result = Vec::default();
        // remove illegal actions
        for action in night_actions {
            match *action {
                NightAction::Heal(ref src, ref tgt) => {
                    let src_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| src == iter_player) { idx } else { continue; };
                    let tgt_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| tgt == iter_player) { idx } else { continue; };
                    let alive = self.alive();
                    if !alive.contains(&src) || !alive.contains(&tgt) { continue; }
                    if result.iter().any(|action| if let NightAction::Heal(ref iter_src, _) = *action { *iter_src == src_idx } else { false }) { continue; }
                    if self.last_heals[src_idx] != Some(tgt_idx) {
                        result.push(NightAction::Heal(src_idx, tgt_idx));
                    }
                }
                NightAction::Investigate(ref src, ref tgt) => {
                    let src_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| src == iter_player) { idx } else { continue; };
                    let tgt_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| tgt == iter_player) { idx } else { continue; };
                    if !self.alive().contains(&src) { continue; }
                    if result.iter().any(|action| if let NightAction::Investigate(ref iter_src, _) = *action { *iter_src == src_idx } else { false }) { continue; }
                    result.push(NightAction::Investigate(src_idx, tgt_idx));
                }
                NightAction::Kill(ref src, ref tgt) => {
                    let src_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| src == iter_player) { idx } else { continue; };
                    let tgt_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| tgt == iter_player) { idx } else { continue; };
                    let alive = self.alive();
                    if !alive.contains(&src) || !alive.contains(&tgt) { continue; }
                    if result.iter().any(|action| if let NightAction::Kill(ref iter_src, _) = *action { *iter_src == src_idx } else { false }) { continue; }
                    result.push(NightAction::Kill(src_idx, tgt_idx));
                }
            }
        }
        // add missing compulsory actions
        for secret_id in 0..self.secret_ids.len() {
            // werewolf kill
            if self.multiverse.alive().contains(&secret_id) && !result.iter().any(|action| if let &NightAction::Kill(src_idx, _) = action { src_idx == secret_id } else { false }) {
                if let Some(random_id) = self.multiverse.alive().into_iter().rand(&mut thread_rng()) {
                    result.push(NightAction::Kill(secret_id, random_id));
                }
            }
        }
        result
    }
/// Remove illegal actions, add missing compulsory actions.
Remove illegal actions, add missing compulsory actions.
Remove illegal actions add missing compulsory actions .
fn sanitized_night_actions(&self, night_actions: &[NightAction<P>]) -> Vec<NightAction<usize>> {
        let mut result = Vec::default();
        // remove illegal actions
        for action in night_actions {
            match *action {
                NightAction::Heal(ref src, ref tgt) => {
                    let src_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| src == iter_player) { idx } else { continue; };
                    let tgt_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| tgt == iter_player) { idx } else { continue; };
                    let alive = self.alive();
                    if !alive.contains(&src) || !alive.contains(&tgt) { continue; }
                    if result.iter().any(|action| if let NightAction::Heal(ref iter_src, _) = *action { *iter_src == src_idx } else { false }) { continue; }
                    if self.last_heals[src_idx] != Some(tgt_idx) {
                        result.push(NightAction::Heal(src_idx, tgt_idx));
                    }
                }
                NightAction::Investigate(ref src, ref tgt) => {
                    let src_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| src == iter_player) { idx } else { continue; };
                    let tgt_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| tgt == iter_player) { idx } else { continue; };
                    if !self.alive().contains(&src) { continue; }
                    if result.iter().any(|action| if let NightAction::Investigate(ref iter_src, _) = *action { *iter_src == src_idx } else { false }) { continue; }
                    result.push(NightAction::Investigate(src_idx, tgt_idx));
                }
                NightAction::Kill(ref src, ref tgt) => {
                    let src_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| src == iter_player) { idx } else { continue; };
                    let tgt_idx = if let Some(idx) = self.secret_ids.iter().position(|iter_player| tgt == iter_player) { idx } else { continue; };
                    let alive = self.alive();
                    if !alive.contains(&src) || !alive.contains(&tgt) { continue; }
                    if result.iter().any(|action| if let NightAction::Kill(ref iter_src, _) = *action { *iter_src == src_idx } else { false }) { continue; }
                    result.push(NightAction::Kill(src_idx, tgt_idx));
                }
            }
        }
        // add missing compulsory actions
        for secret_id in 0..self.secret_ids.len() {
            // werewolf kill
            if self.multiverse.alive().contains(&secret_id) && !result.iter().any(|action| if let &NightAction::Kill(src_idx, _) = action { src_idx == secret_id } else { false }) {
                if let Some(random_id) = self.multiverse.alive().into_iter().rand(&mut thread_rng()) {
                    result.push(NightAction::Kill(secret_id, random_id));
                }
            }
        }
        result
    }
fn sanitized_night_actions ( & self , night_actions : & [ NightAction < P > ] ) -> Vec < NightAction < usize > > { let mut result = Vec :: default ( ) ; // remove illegal actions for action in night_actions { match * action { NightAction :: Heal ( ref src , ref tgt ) => { let src_idx = if let Some ( idx ) = self . secret_ids . iter ( ) . position ( | iter_player | src == iter_player ) { idx } else { continue ; } ; let tgt_idx = if let Some ( idx ) = self . secret_ids . iter ( ) . position ( | iter_player | tgt == iter_player ) { idx } else { continue ; } ; let alive = self . alive ( ) ; if ! alive . contains ( & src ) || ! alive . contains ( & tgt ) { continue ; } if result . iter ( ) . any ( | action | if let NightAction :: Heal ( ref iter_src , _ ) = * action { * iter_src == src_idx } else { false } ) { continue ; } if self . last_heals [ src_idx ] != Some ( tgt_idx ) { result . push ( NightAction :: Heal ( src_idx , tgt_idx ) ) ; } } NightAction :: Investigate ( ref src , ref tgt ) => { let src_idx = if let Some ( idx ) = self . secret_ids . iter ( ) . position ( | iter_player | src == iter_player ) { idx } else { continue ; } ; let tgt_idx = if let Some ( idx ) = self . secret_ids . iter ( ) . position ( | iter_player | tgt == iter_player ) { idx } else { continue ; } ; if ! self . alive ( ) . contains ( & src ) { continue ; } if result . iter ( ) . any ( | action | if let NightAction :: Investigate ( ref iter_src , _ ) = * action { * iter_src == src_idx } else { false } ) { continue ; } result . push ( NightAction :: Investigate ( src_idx , tgt_idx ) ) ; } NightAction :: Kill ( ref src , ref tgt ) => { let src_idx = if let Some ( idx ) = self . secret_ids . iter ( ) . position ( | iter_player | src == iter_player ) { idx } else { continue ; } ; let tgt_idx = if let Some ( idx ) = self . secret_ids . iter ( ) . position ( | iter_player | tgt == iter_player ) { idx } else { continue ; } ; let alive = self . alive ( ) ; if ! alive . contains ( & src ) || ! alive . contains ( & tgt ) { continue ; } if result . iter ( ) . any ( | action | if let NightAction :: Kill ( ref iter_src , _ ) = * action { * iter_src == src_idx } else { false } ) { continue ; } result . push ( NightAction :: Kill ( src_idx , tgt_idx ) ) ; } } } // add missing compulsory actions for secret_id in 0 .. self . secret_ids . len ( ) { // werewolf kill if self . multiverse . alive ( ) . contains ( & secret_id ) && ! result . iter ( ) . any ( | action | if let & NightAction :: Kill ( src_idx , _ ) = action { src_idx == secret_id } else { false } ) { if let Some ( random_id ) = self . multiverse . alive ( ) . into_iter ( ) . rand ( & mut thread_rng ( ) ) { result . push ( NightAction :: Kill ( secret_id , random_id ) ) ; } } } result }
Remove illegal actions, add missing compulsory actions.
Remove illegal actions add missing compulsory actions .
&self
night_actions
&[NightAction<P>]
&self
night_actions
&[NightAction<P>]