B:BD[
2.2432] → [
2.2432:2453]
impl ColorBalance {}
impl ColorBalance {
pub fn gen_mana<'a, R: Rng + ?Sized>(
&self,
rng: &'a mut R,
) -> impl Iterator<Item = Color> + 'a {
let colors = Color::all();
let weights = [
self.mundane.max(1),
self.divine.max(1),
self.revelation.max(1),
self.grace.max(1),
self.growth.max(1),
self.crusade.max(1),
self.suffering.max(1),
];
let dist = WeightedIndex::new(weights).unwrap();
rng.sample_iter(dist).map(move |idx| colors[idx])
}
}
#[cfg(test)]
mod tests {
use super::Color;
#[test]
fn test_color_oppose_and_adjacent() {
let color = Color::Divine;
assert_eq!(Color::Growth, color.opposes());
assert_eq!([Color::Suffering, Color::Revelation], color.adjacent_to());
}
}