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));
}