Skip to content

Commit

Permalink
feat: remove hard rule for sample to have Rain of Chaos card
Browse files Browse the repository at this point in the history
  • Loading branch information
shonya3 committed Jun 27, 2024
1 parent c01ba5a commit 47d1346
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
4 changes: 0 additions & 4 deletions divi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub enum Error {
ParseIntError(ParseIntError),
CsvError(CsvError),
NinjaError(NinjaError),
SampleMustHaveRainOfChaos,
}

impl Display for Error {
Expand All @@ -30,9 +29,6 @@ impl Display for Error {
Error::ParseIntError(err) => err.fmt(f),
Error::CsvError(err) => err.fmt(f),
Error::NinjaError(err) => err.fmt(f),
Error::SampleMustHaveRainOfChaos => {
f.write_str("Sample must have rain of chaos cards.")
}
}
}
}
Expand Down
26 changes: 7 additions & 19 deletions divi/src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Sample {
};
}

sample.write_weight()?;
sample.write_weight();
Ok(sample)
}

Expand Down Expand Up @@ -119,7 +119,7 @@ impl Sample {
card.set_amount(amount);
}

merged.write_weight()?;
merged.write_weight();
Ok(merged)
}

Expand All @@ -132,22 +132,16 @@ impl Sample {
}

/// (After parsing) Calculates special weight for each card and mutates it. Runs at the end of parsing.
fn write_weight(&mut self) -> Result<(), Error> {
let rain_of_chaos_amount = self
.cards
.get("Rain of Chaos")
.ok_or(Error::SampleMustHaveRainOfChaos)?
.amount;
if rain_of_chaos_amount == 0 {
return Err(Error::SampleMustHaveRainOfChaos);
}
fn write_weight(&mut self) {
let Some(rain_of_chaos_amount) = self.cards.get("Rain of Chaos").map(|card| card.amount)
else {
return;
};
let weight_multiplier = RAIN_OF_CHAOS_CONDENSED_WEIGHT / rain_of_chaos_amount as f32;
self.cards.iter_mut().for_each(|card| {
card.weight =
Some((weight_multiplier * card.amount as f32).powf(1.0 / CONDENSING_FACTOR));
});

Ok(())
}

#[must_use]
Expand Down Expand Up @@ -487,10 +481,4 @@ Encroaching Darkness,5\r\nThe Endless Darkness,1\r\nThe Endurance,19\r\nThe Enfo

assert_eq!(rain_of_chaos.amount, 1779);
}

#[test]
fn must_have_rain_of_chaos() {
let result = Sample::create(Input::Csv("name,amount\nThe Doctor,1".to_owned()), None);
assert!(result.is_err());
}
}

0 comments on commit 47d1346

Please sign in to comment.