simplify populate_self_from_children

This commit is contained in:
Simon Gardling 2025-04-29 18:20:53 -04:00
parent 967f1f6efb
commit 9342760d82
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -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,
)
});
}
}