simplify populate_self_from_children
This commit is contained in:
parent
967f1f6efb
commit
9342760d82
@ -57,18 +57,14 @@ impl MoveValueStats {
|
||||
}
|
||||
|
||||
pub fn populate_self_from_children(&mut self, others: &[Self]) {
|
||||
self.wins = others
|
||||
.iter()
|
||||
.map(|x| x.wins + (x.state == Some(MVSGameState::Win)) as u16)
|
||||
.sum::<u16>();
|
||||
self.losses = others
|
||||
.iter()
|
||||
.map(|x| x.losses + (x.state == Some(MVSGameState::Loss)) as u16)
|
||||
.sum::<u16>();
|
||||
self.ties = others
|
||||
.iter()
|
||||
.map(|x| x.ties + (x.state == Some(MVSGameState::Tie)) as u16)
|
||||
.sum::<u16>();
|
||||
(self.wins, self.losses, self.ties) =
|
||||
others.iter().fold((0, 0, 0), |(wins, losses, ties), x| {
|
||||
(
|
||||
wins + x.wins + (x.state == Some(MVSGameState::Win)) as u16,
|
||||
losses + x.losses + (x.state == Some(MVSGameState::Loss)) as u16,
|
||||
ties + x.ties + (x.state == Some(MVSGameState::Tie)) as u16,
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user