From b1bf4a90b7f152766b15a5a8ba793b59332064ed Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 6 Nov 2024 21:49:03 -0700 Subject: [PATCH] tools/match_win: add --- docs/_data/nav/tools.yml | 3 + docs/tools/match_win.html | 18 ++++++ scripts/app_tools_match_win.ts | 5 ++ .../tools/match_win/AppToolsMatchWin.svelte | 59 +++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 docs/tools/match_win.html create mode 100644 scripts/app_tools_match_win.ts create mode 100644 scripts/tools/match_win/AppToolsMatchWin.svelte diff --git a/docs/_data/nav/tools.yml b/docs/_data/nav/tools.yml index bd50e727..6c495f57 100644 --- a/docs/_data/nav/tools.yml +++ b/docs/_data/nav/tools.yml @@ -26,3 +26,6 @@ - name: Time Perception desc: It's later than you think! href: tools/time + - name: Match Win Calculator + desc: Calculate the probability of winning first-to-n/best-of-(2n-1) + href: tools/match_win diff --git a/docs/tools/match_win.html b/docs/tools/match_win.html new file mode 100644 index 00000000..037d3c23 --- /dev/null +++ b/docs/tools/match_win.html @@ -0,0 +1,18 @@ +--- +title: Match Win Calculator +date: "2024-11-06 21:48:00 -0700" +entry: app_tools_match_win +--- +

+ Many games and sports play multiple rounds, also known as first-to-n or best-of-(2n-1). + This structure amplifies skill gaps, as the underdog is more likely to lose the match than an individual round, which can be calculated with a negative binomial distribution. +

+ +

+ In the table below, the row corresponds to the number of points for the opponent, and + the column corresponds to the number of points for the current player. + The cell shows the probability that the current player wins the match. + Double-click the slider for P to reset to 0.5. +

+ +{% include app.html %} diff --git a/scripts/app_tools_match_win.ts b/scripts/app_tools_match_win.ts new file mode 100644 index 00000000..42fc0db7 --- /dev/null +++ b/scripts/app_tools_match_win.ts @@ -0,0 +1,5 @@ +import AppToolsMatchWin from './tools/match_win/AppToolsMatchWin.svelte' + +import loadApp from './victorz/app' + +loadApp(AppToolsMatchWin) diff --git a/scripts/tools/match_win/AppToolsMatchWin.svelte b/scripts/tools/match_win/AppToolsMatchWin.svelte new file mode 100644 index 00000000..43e1901f --- /dev/null +++ b/scripts/tools/match_win/AppToolsMatchWin.svelte @@ -0,0 +1,59 @@ + + +

N (number of rounds to win)

+ + + +

P (probability of winning a round)

+ + $p = 0.5}> + + + + + + + + + + {#each memo as _, i} + + {/each} + + + + {#each memo as row, i} + + {#if !i} + + {/if} + + {#each row as v} + {@const balanced = v * (1-v) * 2} + + {/each} + + {/each} + +
Probability of winning first-to-{$n}/best-of-{2*$n-1}
Player score
{i}
Opponent score
{i} + {v.toFixed(5)} +