Skip to content

Commit

Permalink
Improve scoring
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 18, 2023
1 parent ab27a4d commit 658d655
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
19 changes: 9 additions & 10 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct AudioAssets {
pub guitar_sounds: Vec<Handle<AudioSource>>,
#[asset(paths("audio/unicorn0.ogg", "audio/unicorn1.ogg"), collection(typed))]
pub unicorn_sounds: Vec<Handle<AudioSource>>,

#[cfg(not(feature = "web"))]
#[asset(path = "music/ingame.ogg")]
pub music: Handle<AudioSource>,
Expand All @@ -56,18 +57,16 @@ pub struct AudioAssets {
impl AudioAssets {
pub fn get_sfx(&self, kind: SoundEffectKind) -> Handle<AudioSource> {
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()
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/simulation/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f64>() / 3.0;

scores
}
}
Expand Down
19 changes: 8 additions & 11 deletions src/state/results_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/state/title_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn enter_title_screen(mut commands: Commands, root: Res<AppRoot>, config: Res<Co
TextSection::new(
line[1],
TextStyle {
font: FONT_HANDLE,
font: BOLD_FONT_HANDLE,
color: config.hyperlink_text_color,
..default()
},
Expand Down
2 changes: 1 addition & 1 deletion src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ generate_upgrade_list!(
name: "RepulsionPlugin".to_string(),
desc: "Repels entities away from the cursor. Makes your game more fun.".to_string(),
tech_debt: 1.0,
fun_score: 10.0,
fun_score: 20.0,
base_cost: 2_000.0,
cost_scale_factor: 1.2,
weight: 0.25,
Expand Down

0 comments on commit 658d655

Please sign in to comment.