use super::*;
pub(crate) const GEM_OF_ORDER: Card = Card {
name: Name::GemOfOrder,
suit: Suit::Artifact,
strength: 5,
adder: None,
wild: None,
modifier: None,
immunity: None,
blanks: None,
bonus: Some(gem_of_order_bonus),
penalty: None,
};
pub(crate) fn gem_of_order_bonus(hand: &ScoringHand) -> i16 {
let mut strengths: Vec<i16> = hand.cards.iter().map(|card| card.strength).collect();
strengths.sort();
strengths.dedup();
if strengths.len() < 3 {
0
} else {
let run_length = strengths.windows(2)
.fold((1u8, 1u8), |(max_run, current_run), window| {
if window[1] == window[0] + 1 {
let new_current = current_run + 1;
(max_run.max(new_current), new_current)
} else {
(max_run, 1)
}
})
.0;
match run_length {
3 => 10,
4 => 30,
5 => 60,
6 => 100,
7 => 150,
_ => 0,
}
}
}