From 658d655754e878f94e86659c7d64e1631052a69c Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Sun, 17 Dec 2023 16:06:28 -0800 Subject: [PATCH] Improve scoring --- src/audio.rs | 19 +++++++++---------- src/simulation/score.rs | 16 ++++++++++++---- src/state/results_screen.rs | 19 ++++++++----------- src/state/title_screen.rs | 2 +- src/upgrade.rs | 2 +- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/audio.rs b/src/audio.rs index 429e850..c1f486d 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -48,6 +48,7 @@ pub struct AudioAssets { pub guitar_sounds: Vec>, #[asset(paths("audio/unicorn0.ogg", "audio/unicorn1.ogg"), collection(typed))] pub unicorn_sounds: Vec>, + #[cfg(not(feature = "web"))] #[asset(path = "music/ingame.ogg")] pub music: Handle, @@ -56,18 +57,16 @@ pub struct AudioAssets { impl AudioAssets { pub fn get_sfx(&self, kind: SoundEffectKind) -> Handle { use SoundEffectKind::*; - macro_rules! select_from { - ($a:expr) => { - $a.choose(&mut thread_rng()).unwrap().clone() - }; - } match kind { - DefaultUpgrade => select_from!(self.upgrade_sounds), - Keyboard => select_from!(self.keyboard_sounds), - Backspace => self.backspace_sound.clone(), - Guitar => select_from!(self.guitar_sounds), - Unicorn => select_from!(self.unicorn_sounds), + DefaultUpgrade => &self.upgrade_sounds, + Keyboard => &self.keyboard_sounds, + Backspace => return self.backspace_sound.clone(), + Guitar => &self.guitar_sounds, + Unicorn => &self.unicorn_sounds, } + .choose(&mut thread_rng()) + .unwrap() + .clone() } } diff --git a/src/simulation/score.rs b/src/simulation/score.rs index 7ff4abd..d17676b 100644 --- a/src/simulation/score.rs +++ b/src/simulation/score.rs @@ -25,18 +25,26 @@ impl Simulation { /// 2. Presentation /// 3. Theme Interpretation /// 4. Overall - pub fn calculate_scores(&self) -> [f64; 4] { + pub fn calculate_scores(&self, ratings: f64) -> [f64; 4] { let mut scores: [f64; 4] = [ // Fun - calculate_score(self.fun_score, 0.0, 17.5), + calculate_score(self.fun_score, 0.0, 28.0), // Presentation - calculate_score(self.presentation_score, 0.0, 21.0), + calculate_score(self.presentation_score, 0.0, 30.0), // Theme Interpretation - calculate_score((self.entities.abs() + 1.0).log10(), -20.0, 40.0), + calculate_score((self.entities.abs() + 1.0).log10(), 0.0, 50.0), // Overall 0.0, ]; + + // Floor scores to multiples of 1 / ratings + for score in &mut scores { + *score = (*score * ratings).floor() / ratings + } + + // Calculate overall score scores[3] = scores.iter().sum::() / 3.0; + scores } } diff --git a/src/state/results_screen.rs b/src/state/results_screen.rs index 4b212df..7940aac 100644 --- a/src/state/results_screen.rs +++ b/src/state/results_screen.rs @@ -75,8 +75,6 @@ fn enter_results_screen( let config = &config.results_screen; commands.insert_resource(ClearColor(config.background_color)); - let elapsed = time.elapsed_seconds_f64() - start_time.0; - let screen = commands .spawn(( Name::new("ResultsScreen"), @@ -169,16 +167,18 @@ fn enter_results_screen( .set_parent(cell); } - let scores: [f64; 4] = simulation.calculate_scores(); + const SUBMISSIONS: f64 = 90.0; + const LO: f64 = 1.5; + const HI: f64 = 4.8; + let elapsed = time.elapsed_seconds_f64() - start_time.0; + let ratings = (elapsed / 60.0).clamp(5.0, 120.0); + let scores: [f64; 4] = simulation.calculate_scores(ratings); for (row, (&criterion, score)) in TABLE_CRITERIA_TEXT .iter() .zip(scores.into_iter()) .enumerate() { - const SUBMISSIONS: f64 = 83.0; - const LO: f64 = 1.5; - const HI: f64 = 4.9; - // Clamp score to the interval [LO, HI] and then linearly map to the interval [1, SUBMISSIONS] + // Calculate rank by linearly mapping score from [LO, HI] to [1, SUBMISSIONS] let rank = (1.0 - (score.clamp(LO, HI) - LO) / (HI - LO)) * (SUBMISSIONS - 1.0) + 1.0; let entries = [ @@ -245,10 +245,7 @@ fn enter_results_screen( .spawn(( Name::new("RankedText"), TextBundle::from_section( - format!( - "Ranked from {} ratings.", - ((elapsed / 60.0) as usize).clamp(5, 120), - ), + format!("Ranked from {ratings:.0} ratings."), TextStyle { font: FONT_HANDLE, color: config.text_color, diff --git a/src/state/title_screen.rs b/src/state/title_screen.rs index cd2bd5b..b3f6607 100644 --- a/src/state/title_screen.rs +++ b/src/state/title_screen.rs @@ -195,7 +195,7 @@ fn enter_title_screen(mut commands: Commands, root: Res, config: Res