Skip to content

Commit

Permalink
improve statistical test of getWinningBuzzer
Browse files Browse the repository at this point in the history
(and add UI change for vercel debug)
  • Loading branch information
neilmovva committed Feb 25, 2024
1 parent fdc390b commit 5c4c56c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default function Header({
<div className="flex items-center justify-between">
<Link to="/">
<h1 className="text-shadow-md font-korinna text-2xl font-bold text-white">
Jep!
Nep!
</h1>
</Link>
<div className="flex items-center gap-2">
Expand Down
15 changes: 9 additions & 6 deletions app/engine/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2208,19 +2208,22 @@ describe("gameEngine", () => {
});

describe("getWinningBuzzer", () => {
it("returns the buzz of the lower user ID in case of a tie", () => {
it("measures the buzzer winrate between two equally fast players over 1000 trials. Expected to be near 50-50", () => {
let player1Wins = 0;
for (let charCode = 16; charCode <= 116; charCode++) {
let tiebreakSeed = String.fromCharCode(charCode);
let buzzes = new Map();
const n_trials = 1000;
for (let trial = 0; trial < n_trials; trial++) {
const tiebreakSeed = Math.random().toString() + trial.toString();
const buzzes = new Map();
buzzes.set(PLAYER1.userId, 100);
buzzes.set(PLAYER2.userId, 100);
const winner = getWinningBuzzer(buzzes, tiebreakSeed)?.userId;
if (winner === PLAYER1.userId) {
player1Wins++;
}
}
expect(player1Wins).toBeGreaterThan(30);
expect(player1Wins).toBeLessThan(70);
// CDF of bin(n=1000, p=0.5) = 0.99999 @ k = 435
const k = 435;
expect(player1Wins).toBeGreaterThan(k);
expect(player1Wins).toBeLessThan(n_trials - k);
});
});
9 changes: 1 addition & 8 deletions app/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function getWinningBuzzer(
});

const sortedBuzzes = quantizedBuzzes.sort(
([_a, qDeltaA, tiebreakA], [_b, qDeltaB, tiebreakB]) => {
([, qDeltaA, tiebreakA], [, qDeltaB, tiebreakB]) => {
if (qDeltaA === qDeltaB) {
return tiebreakA - tiebreakB;
} else {
Expand Down Expand Up @@ -432,14 +432,7 @@ export function gameEngine(state: State, action: Action): State {
return;
}
} else {
<<<<<<< HEAD
const winningBuzzer = getWinningBuzzer(
draft.buzzes,
draft.clue?.clue,
);
=======
const winningBuzzer = getWinningBuzzer(draft.buzzes, clueText);
>>>>>>> 7af7760 (use tiebreak at all getWinningBuzzer callsites)
if (userId !== winningBuzzer?.userId) {
return;
}
Expand Down

0 comments on commit 5c4c56c

Please sign in to comment.