renamed CatchScoreState fields

This commit is contained in:
MaxOhn
2024-03-03 08:03:05 +01:00
parent cd56bf3e16
commit 3705338d12
4 changed files with 53 additions and 57 deletions
+8 -8
View File
@@ -89,10 +89,10 @@ impl From<ScoreState> for CatchScoreState {
fn from(state: ScoreState) -> Self { fn from(state: ScoreState) -> Self {
Self { Self {
max_combo: state.max_combo, max_combo: state.max_combo,
n_fruits: state.n300, fruits: state.n300,
n_droplets: state.n100, droplets: state.n100,
n_tiny_droplets: state.n50, tiny_droplets: state.n50,
n_tiny_droplet_misses: state.n_katu, tiny_droplet_misses: state.n_katu,
misses: state.misses, misses: state.misses,
} }
} }
@@ -144,10 +144,10 @@ impl From<CatchScoreState> for ScoreState {
Self { Self {
max_combo: state.max_combo, max_combo: state.max_combo,
n_geki: 0, n_geki: 0,
n_katu: state.n_tiny_droplet_misses, n_katu: state.tiny_droplet_misses,
n300: state.n_fruits, n300: state.fruits,
n100: state.n_droplets, n100: state.droplets,
n50: state.n_tiny_droplets, n50: state.tiny_droplets,
misses: state.misses, misses: state.misses,
} }
} }
+9 -9
View File
@@ -34,7 +34,7 @@ use crate::{
/// ///
/// // The first 10 hitresults are only fruits /// // The first 10 hitresults are only fruits
/// for _ in 0..10 { /// for _ in 0..10 {
/// state.n_fruits += 1; /// state.fruits += 1;
/// state.max_combo += 1; /// state.max_combo += 1;
/// ///
/// let attrs = gradual.next(state.clone()).unwrap(); /// let attrs = gradual.next(state.clone()).unwrap();
@@ -52,15 +52,15 @@ use crate::{
/// // Notice how tiny droplets from sliders do not count as hit objects /// // Notice how tiny droplets from sliders do not count as hit objects
/// // that require processing. Only fruits and droplets do. /// // that require processing. Only fruits and droplets do.
/// // Also notice how all 10 objects will be processed in one go. /// // Also notice how all 10 objects will be processed in one go.
/// state.n_fruits += 4; /// state.fruits += 4;
/// state.n_droplets += 6; /// state.droplets += 6;
/// state.n_tiny_droplets += 12; /// state.tiny_droplets += 12;
/// // The `nth` method takes a zero-based value. /// // The `nth` method takes a zero-based value.
/// let attrs = gradual.nth(state.clone(), 9).unwrap(); /// let attrs = gradual.nth(state.clone(), 9).unwrap();
/// println!("PP: {}", attrs.pp); /// println!("PP: {}", attrs.pp);
/// ///
/// // Now comes another fruit. Note that the max combo gets incremented again. /// // Now comes another fruit. Note that the max combo gets incremented again.
/// state.n_fruits += 1; /// state.fruits += 1;
/// state.max_combo += 1; /// state.max_combo += 1;
/// let attrs = gradual.next(state.clone()).unwrap(); /// let attrs = gradual.next(state.clone()).unwrap();
/// println!("PP: {}", attrs.pp); /// println!("PP: {}", attrs.pp);
@@ -68,10 +68,10 @@ use crate::{
/// // Skip to the end /// // Skip to the end
/// # /* /// # /*
/// state.max_combo = ... /// state.max_combo = ...
/// state.n_fruits = ... /// state.fruits = ...
/// state.n_droplets = ... /// state.droplets = ...
/// state.n_tiny_droplets = ... /// state.tiny_droplets = ...
/// state.n_tiny_droplet_misses = ... /// state.tiny_droplet_misses = ...
/// state.misses = ... /// state.misses = ...
/// # */ /// # */
/// let attrs = gradual.last(state.clone()).unwrap(); /// let attrs = gradual.last(state.clone()).unwrap();
+26 -26
View File
@@ -150,10 +150,10 @@ impl<'map> CatchPerformance<'map> {
pub const fn state(mut self, state: CatchScoreState) -> Self { pub const fn state(mut self, state: CatchScoreState) -> Self {
let CatchScoreState { let CatchScoreState {
max_combo, max_combo,
n_fruits, fruits: n_fruits,
n_droplets, droplets: n_droplets,
n_tiny_droplets, tiny_droplets: n_tiny_droplets,
n_tiny_droplet_misses, tiny_droplet_misses: n_tiny_droplet_misses,
misses, misses,
} = state; } = state;
@@ -249,8 +249,8 @@ impl<'map> CatchPerformance<'map> {
} }
}; };
best_state.n_fruits = n_fruits; best_state.fruits = n_fruits;
best_state.n_droplets = n_droplets; best_state.droplets = n_droplets;
let mut find_best_tiny_droplets = |acc: f64| { let mut find_best_tiny_droplets = |acc: f64| {
let raw_tiny_droplets = acc let raw_tiny_droplets = acc
@@ -275,8 +275,8 @@ impl<'map> CatchPerformance<'map> {
if curr_dist < best_dist { if curr_dist < best_dist {
best_dist = curr_dist; best_dist = curr_dist;
best_state.n_tiny_droplets = n_tiny_droplets; best_state.tiny_droplets = n_tiny_droplets;
best_state.n_tiny_droplet_misses = n_tiny_droplet_misses; best_state.tiny_droplet_misses = n_tiny_droplet_misses;
} }
} }
}; };
@@ -287,8 +287,8 @@ impl<'map> CatchPerformance<'map> {
Some(acc) => { Some(acc) => {
match (n_tiny_droplets + n_tiny_droplet_misses).cmp(&attrs.n_tiny_droplets) { match (n_tiny_droplets + n_tiny_droplet_misses).cmp(&attrs.n_tiny_droplets) {
Ordering::Equal => { Ordering::Equal => {
best_state.n_tiny_droplets = n_tiny_droplets; best_state.tiny_droplets = n_tiny_droplets;
best_state.n_tiny_droplet_misses = n_tiny_droplet_misses; best_state.tiny_droplet_misses = n_tiny_droplet_misses;
} }
Ordering::Less | Ordering::Greater => find_best_tiny_droplets(acc), Ordering::Less | Ordering::Greater => find_best_tiny_droplets(acc),
} }
@@ -298,24 +298,24 @@ impl<'map> CatchPerformance<'map> {
.n_tiny_droplets .n_tiny_droplets
.saturating_sub(n_tiny_droplets + n_tiny_droplet_misses); .saturating_sub(n_tiny_droplets + n_tiny_droplet_misses);
best_state.n_tiny_droplets = n_tiny_droplets + n_remaining; best_state.tiny_droplets = n_tiny_droplets + n_remaining;
best_state.n_tiny_droplet_misses = n_tiny_droplet_misses; best_state.tiny_droplet_misses = n_tiny_droplet_misses;
} }
}, },
(Some(n_tiny_droplets), None) => { (Some(n_tiny_droplets), None) => {
best_state.n_tiny_droplets = cmp::min(attrs.n_tiny_droplets, n_tiny_droplets); best_state.tiny_droplets = cmp::min(attrs.n_tiny_droplets, n_tiny_droplets);
best_state.n_tiny_droplet_misses = best_state.tiny_droplet_misses =
attrs.n_tiny_droplets.saturating_sub(n_tiny_droplets); attrs.n_tiny_droplets.saturating_sub(n_tiny_droplets);
} }
(None, Some(n_tiny_droplet_misses)) => { (None, Some(n_tiny_droplet_misses)) => {
best_state.n_tiny_droplets = best_state.tiny_droplets =
attrs.n_tiny_droplets.saturating_sub(n_tiny_droplet_misses); attrs.n_tiny_droplets.saturating_sub(n_tiny_droplet_misses);
best_state.n_tiny_droplet_misses = best_state.tiny_droplet_misses =
cmp::min(attrs.n_tiny_droplets, n_tiny_droplet_misses); cmp::min(attrs.n_tiny_droplets, n_tiny_droplet_misses);
} }
(None, None) => match self.acc { (None, None) => match self.acc {
Some(acc) => find_best_tiny_droplets(acc), Some(acc) => find_best_tiny_droplets(acc),
None => best_state.n_tiny_droplets = attrs.n_tiny_droplets, None => best_state.tiny_droplets = attrs.n_tiny_droplets,
}, },
} }
@@ -524,7 +524,7 @@ impl CatchPerformanceInner {
} }
const fn combo_hits(&self) -> u32 { const fn combo_hits(&self) -> u32 {
self.state.n_fruits + self.state.n_droplets + self.state.misses self.state.fruits + self.state.droplets + self.state.misses
} }
} }
@@ -636,8 +636,8 @@ mod test {
} }
}; };
best_state.n_fruits = new_fruits; best_state.fruits = new_fruits;
best_state.n_droplets = new_droplets; best_state.droplets = new_droplets;
let (min_tiny_droplets, max_tiny_droplets) = match (n_tiny_droplets, n_tiny_droplet_misses) let (min_tiny_droplets, max_tiny_droplets) = match (n_tiny_droplets, n_tiny_droplet_misses)
{ {
@@ -676,8 +676,8 @@ mod test {
if curr_dist < best_dist { if curr_dist < best_dist {
best_dist = curr_dist; best_dist = curr_dist;
best_state.n_tiny_droplets = new_tiny_droplets; best_state.tiny_droplets = new_tiny_droplets;
best_state.n_tiny_droplet_misses = new_tiny_droplet_misses; best_state.tiny_droplet_misses = new_tiny_droplet_misses;
} }
} }
@@ -746,10 +746,10 @@ mod test {
let expected = CatchScoreState { let expected = CatchScoreState {
max_combo: N_FRUITS + N_DROPLETS - 2, max_combo: N_FRUITS + N_DROPLETS - 2,
n_fruits: N_FRUITS - 2, fruits: N_FRUITS - 2,
n_droplets: N_DROPLETS, droplets: N_DROPLETS,
n_tiny_droplets: N_TINY_DROPLETS - 20, tiny_droplets: N_TINY_DROPLETS - 20,
n_tiny_droplet_misses: 20, tiny_droplet_misses: 20,
misses: 2, misses: 2,
}; };
+10 -14
View File
@@ -7,13 +7,13 @@ pub struct CatchScoreState {
/// Note that only fruits and droplets are considered for osu!catch combo. /// Note that only fruits and droplets are considered for osu!catch combo.
pub max_combo: u32, pub max_combo: u32,
/// Amount of current fruits (300s). /// Amount of current fruits (300s).
pub n_fruits: u32, pub fruits: u32,
/// Amount of current droplets (100s). /// Amount of current droplets (100s).
pub n_droplets: u32, pub droplets: u32,
/// Amount of current tiny droplets (50s). /// Amount of current tiny droplets (50s).
pub n_tiny_droplets: u32, pub tiny_droplets: u32,
/// Amount of current tiny droplet misses (katus). /// Amount of current tiny droplet misses (katus).
pub n_tiny_droplet_misses: u32, pub tiny_droplet_misses: u32,
/// Amount of current misses (fruits and droplets). /// Amount of current misses (fruits and droplets).
pub misses: u32, pub misses: u32,
} }
@@ -23,21 +23,17 @@ impl CatchScoreState {
pub const fn new() -> Self { pub const fn new() -> Self {
Self { Self {
max_combo: 0, max_combo: 0,
n_fruits: 0, fruits: 0,
n_droplets: 0, droplets: 0,
n_tiny_droplets: 0, tiny_droplets: 0,
n_tiny_droplet_misses: 0, tiny_droplet_misses: 0,
misses: 0, misses: 0,
} }
} }
/// Return the total amount of hits by adding everything up. /// Return the total amount of hits by adding everything up.
pub const fn total_hits(&self) -> u32 { pub const fn total_hits(&self) -> u32 {
self.n_fruits self.fruits + self.droplets + self.tiny_droplets + self.tiny_droplet_misses + self.misses
+ self.n_droplets
+ self.n_tiny_droplets
+ self.n_tiny_droplet_misses
+ self.misses
} }
/// Calculate the accuracy between `0.0` and `1.0` for this state. /// Calculate the accuracy between `0.0` and `1.0` for this state.
@@ -48,7 +44,7 @@ impl CatchScoreState {
return 0.0; return 0.0;
} }
let numerator = self.n_fruits + self.n_droplets + self.n_tiny_droplets; let numerator = self.fruits + self.droplets + self.tiny_droplets;
let denominator = total_hits; let denominator = total_hits;
f64::from(numerator) / f64::from(denominator) f64::from(numerator) / f64::from(denominator)