diff --git a/zenno/src/routes/doc/fans/+page.svelte b/zenno/src/routes/doc/fans/+page.svelte index 9d0913e..b04c345 100644 --- a/zenno/src/routes/doc/fans/+page.svelte +++ b/zenno/src/routes/doc/fans/+page.svelte @@ -41,6 +41,30 @@ [18, 1], ] as const; + const margins = [ + ['Nose', 0], + ['Head', 0], + ['Neck', 0], + ['1/2 L', 0.5], + ['3/4 L', 0.75], + ['1 L', 1], + ['1 1/4 L', 1.25], + ['1 1/2 L', 1.5], + ['1 3/4 L', 1.75], + ['2 L', 2], + ['2 1/2 L', 2.5], + ['3 L', 3], + ['3 1/2 L', 3.5], + ['4 L', 4], + ['5 L', 5], + ['6 L', 6], + ['7 L', 7], + ['8 L', 8], + ['9 L', 9], + ['10 L', 10], + ['Distance', 11], + ] as const; + const marginBonus = [ ['Nose – 3/4 L', 0, 9], ['1 L – 2.5 L', 2, 6], @@ -107,7 +131,11 @@
- +
@@ -157,7 +185,7 @@ - + @@ -174,7 +202,10 @@
Actual
Margin Within
Margin Within Bonus for Winner Bonus for Podium
Fans from Skill Activations -

The trainee receives a bonus percentage of base fans according to the number of skills she activated during the race.

+

+ The trainee receives a bonus percentage of base fans according to the number of skills she activated during the race. Negative + (purple) skills count toward this count. +

@@ -218,7 +249,10 @@ -
  • (Trackblazer/MANT) If glowsticks were used for the race, apply their multiplier and round down.
  • +
  • + (Trackblazer/MANT) If glowsticks were used for the race, apply their multiplier, then round by the same + five-significant-figures procedure. +
  • Data diff --git a/zenno/src/routes/doc/fans/fans.spec.ts b/zenno/src/routes/doc/fans/fans.spec.ts new file mode 100644 index 0000000..38165c9 --- /dev/null +++ b/zenno/src/routes/doc/fans/fans.spec.ts @@ -0,0 +1,28 @@ +import { expect, test } from 'vitest'; +import * as fans from './fans'; + +interface FansGainedCase { + b: number; + fb: number; + ord: number; + m: number; + s: number; + gs?: number; + want: number; +} + +test.for([ + { b: 700, fb: 88, ord: 1, m: 1, s: 0, want: 1342 }, + { b: 10500, fb: 105, ord: 1, m: 1, s: 0, want: 21956 }, + { b: 2000, fb: 88, ord: 10, m: 10, s: 1, want: 191 }, + { b: 30000, fb: 75, ord: 1, m: 5, s: 4, gs: 50, want: 85838 }, + { b: 30000, fb: 95, ord: 1, m: 9, s: 8, gs: 50, want: 100040 }, + { b: 30000, fb: 105, ord: 1, m: 5, s: 5, gs: 50, want: 100550 }, +])('%j', (c) => { + const baseFans = fans.baseFans(c.b, c.ord); + const marginFans = fans.marginFans(baseFans, c.ord, c.m); + const skillFans = fans.skillFans(baseFans, c.s); + const itemBonus = c.gs ?? 0; + const got = fans.gained(baseFans, marginFans, skillFans, c.fb, itemBonus); + expect(got).toBe(c.want); +}); diff --git a/zenno/src/routes/doc/fans/fans.ts b/zenno/src/routes/doc/fans/fans.ts index 3fe5f23..cdcbfab 100644 --- a/zenno/src/routes/doc/fans/fans.ts +++ b/zenno/src/routes/doc/fans/fans.ts @@ -53,6 +53,16 @@ export function skillFans(baseFans: number, skillsActivated: number): number { return Math.floor(baseFans * b); } +/** + * Round a number to five significant figures. + * @param x Number to round + * @returns x rounded to five significant figures + */ +function fivesf(x: number): number { + const s = x.toPrecision(5); + return Math.floor(parseFloat(s)); +} + /** * Calculate fan gain from a career race. * @param baseFans Base fans from the race and finish order @@ -64,10 +74,7 @@ export function skillFans(baseFans: number, skillsActivated: number): number { */ export function gained(baseFans: number, marginFans: number, skillFans: number, fanBonus: number, itemBonus?: number): number { const f = baseFans + marginFans + skillFans; - const s = Math.fround(f * Math.fround(1 + fanBonus / 100)); - const p = Math.exp((4 - Math.floor(Math.log10(s))) * Math.LN10); - // Add half a significant figure to account for precision. - const d = Math.floor(Math.round(s * p + 5e-6) / p + 5e-6); + const d = fivesf(Math.fround(f * Math.fround(1 + fanBonus / 100))); const b = itemBonus ?? 0; - return Math.floor(d * (1 + b / 100)); + return fivesf(d * (1 + b / 100)); }