2026-04-08 16:52:10 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Little League World Series (LLWS) Bracket Simulator
|
|
|
|
|
|
*
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
* Monte Carlo simulation of the LLWS (20-team double-elimination format, 2025+).
|
|
|
|
|
|
*
|
|
|
|
|
|
* The tournament is two independent 10-team double-elimination brackets — United
|
|
|
|
|
|
* States and International — each producing a side champion, then a World
|
|
|
|
|
|
* Championship game and a Consolation game between the side runners-up. There is no
|
|
|
|
|
|
* pool play. This mirrors the llws_20 bracket template so simulated placements line
|
|
|
|
|
|
* up with the bracket admins actually score.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
*
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
* Two modes:
|
|
|
|
|
|
* 1. Pre-bracket mode: no llws_20 bracket exists yet (or it has no participants
|
|
|
|
|
|
* seeded). Each side is shuffled into the 10 bracket slots every iteration, so
|
|
|
|
|
|
* the draw is modelled as random.
|
|
|
|
|
|
* 2. Bracket-aware mode: a seeded llws_20 bracket exists. Teams sit in their real
|
|
|
|
|
|
* slots and completed match results are honored rather than re-simulated, so a
|
|
|
|
|
|
* team that has already lost carries that loss into every iteration.
|
|
|
|
|
|
*
|
2026-04-08 16:52:10 -04:00
|
|
|
|
* Algorithm:
|
|
|
|
|
|
* 1. Load all 20 participants for the sports season from DB
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
* 2. Load the llws_20 playoff bracket, if one exists, to get the real draw and
|
|
|
|
|
|
* whatever results have been recorded so far
|
|
|
|
|
|
* 3. Load championship futures odds from participantExpectedValues.sourceOdds
|
2026-04-08 16:52:10 -04:00
|
|
|
|
* (entered via Admin → Futures Odds; American format)
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
* 4. Convert those futures to Elo via the shared probability engine, then drive
|
|
|
|
|
|
* each game with the Elo win probability (see "Why Elo" below)
|
|
|
|
|
|
* 5. Per simulation:
|
|
|
|
|
|
* a. Place each side's 10 teams into the bracket slots (real draw when known,
|
|
|
|
|
|
* otherwise shuffled)
|
|
|
|
|
|
* b. Simulate the 10-team double-elimination bracket for each side, replaying
|
|
|
|
|
|
* completed games from their recorded result (see simulateSideBracket)
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
* c. Consolation game: US side loser vs Intl side loser → 3rd / 4th
|
|
|
|
|
|
* d. World Championship: US champion vs Intl champion → 1st / 2nd
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
* 6. Track placement counts across all simulations
|
|
|
|
|
|
* 7. Convert counts to probability distributions
|
|
|
|
|
|
*
|
|
|
|
|
|
* Why Elo rather than raw futures:
|
|
|
|
|
|
* A championship future already bakes in the ~6 wins needed to lift the trophy, so
|
|
|
|
|
|
* using it directly as a single-game strength (p1 / (p1 + p2)) makes every
|
|
|
|
|
|
* individual game as lopsided as the whole tournament and compounds the favorite's
|
|
|
|
|
|
* edge over and over. convertFuturesToElo undoes that compression first (the
|
|
|
|
|
|
* empirically calibrated cube-root step in decompressProbability) before mapping to
|
|
|
|
|
|
* an Elo scale, which is how the other bracket simulators on the platform consume
|
|
|
|
|
|
* futures. LLWS_PARITY_FACTOR then widens the Elo curve to reflect how much
|
|
|
|
|
|
* single-game variance there is in six-inning Little League baseball.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
*
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
* Side assignment (externalId): "US" or "Intl". The legacy pool suffixes
|
|
|
|
|
|
* ("US:A", "US:B", "Intl:A", "Intl:B") are still accepted and read as the side
|
|
|
|
|
|
* alone, so seasons configured for the old pool-play format keep working — pools
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
* no longer exist, so the suffix has no effect. When a seeded bracket exists the
|
|
|
|
|
|
* bracket's own slots decide the sides and externalId is not consulted.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
*
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
* Placement tiers → SimulationProbabilities mapping (matches llws_20's scoring):
|
|
|
|
|
|
* probFirst = World Championship winner (1 per sim)
|
|
|
|
|
|
* probSecond = World Championship loser (1 per sim)
|
|
|
|
|
|
* probThird = Consolation winner (1 per sim)
|
|
|
|
|
|
* probFourth = Consolation loser (1 per sim)
|
|
|
|
|
|
* probFifth/probSixth = Elimination Final losers (2 per sim — 1 per side)
|
|
|
|
|
|
* probSeventh/probEighth = Elimination Round 4 losers (2 per sim — 1 per side)
|
|
|
|
|
|
* Everyone else → all 0 (12 teams out in Elimination Rounds 1–3)
|
2026-04-08 16:52:10 -04:00
|
|
|
|
*
|
|
|
|
|
|
* Admin setup:
|
|
|
|
|
|
* 1. Create a Sport with simulatorType = "llws_bracket"
|
|
|
|
|
|
* 2. Create a Sports Season and add exactly 20 participants (10 US, 10 International)
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
* 3. Set externalId on each participant via Admin → Manage Participants to "US" or
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
* "Intl" (optional — names starting with "US " infer US, all others infer Intl).
|
|
|
|
|
|
* Once the bracket is generated and seeded this is no longer used.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
* 4. Enter championship futures odds via Admin → Futures Odds (sourceOdds)
|
|
|
|
|
|
* 5. Run simulation via Admin → Simulate
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import { database } from "~/database/context";
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
import { and, eq } from "drizzle-orm";
|
2026-04-08 16:52:10 -04:00
|
|
|
|
import * as schema from "~/database/schema";
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
import {
|
|
|
|
|
|
convertFuturesToElo,
|
|
|
|
|
|
eloWinProbabilityWithParity,
|
|
|
|
|
|
} from "~/services/probability-engine";
|
|
|
|
|
|
import { llwsMatchNumber } from "~/lib/bracket-templates";
|
2026-04-08 16:52:10 -04:00
|
|
|
|
import type { Simulator, SimulationResult } from "./types";
|
2026-06-30 23:24:48 +00:00
|
|
|
|
import { positiveConfigNumber } from "./config-access";
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
|
|
|
|
|
// ─── Simulation parameters ────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
const NUM_SIMULATIONS = 50_000;
|
|
|
|
|
|
const US_TEAM_COUNT = 10;
|
|
|
|
|
|
const INTL_TEAM_COUNT = 10;
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const DEFAULT_ELO = 1500;
|
|
|
|
|
|
const LLWS_TEMPLATE_ID = "llws_20";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Elo scaling for a single LLWS game.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Much higher than the 400-point standard because a six-inning Little League game
|
|
|
|
|
|
* between 12-year-olds is far closer to a coin flip than a pro game: one pitcher, one
|
|
|
|
|
|
* big inning, and the mercy rule all compress the gap.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Calibrated by sweeping this value until a randomized-draw simulation reproduces the
|
|
|
|
|
|
* championship futures it was fed. Against a representative 20-team futures board,
|
|
|
|
|
|
* simulated championship probability vs. the market it came from:
|
|
|
|
|
|
* parity 400 → favorite 21.8% priced, 51.5% simulated (RMSE 0.075)
|
|
|
|
|
|
* parity 700 → favorite 21.8% priced, 31.5% simulated (RMSE 0.026)
|
|
|
|
|
|
* parity 1000 → favorite 21.8% priced, 21.8% simulated (RMSE 0.003) ← chosen
|
|
|
|
|
|
* parity 1200 → favorite 21.8% priced, 18.3% simulated (RMSE 0.010)
|
|
|
|
|
|
* Overridable per season via the `parityFactor` simulator config.
|
|
|
|
|
|
*/
|
|
|
|
|
|
const LLWS_PARITY_FACTOR = 1_000;
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
|
|
|
|
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
type Side = "US" | "Intl";
|
|
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
/** Bracket-template side index: U.S. matches take the low match numbers. */
|
|
|
|
|
|
const SIDE_INDEX: Record<Side, 0 | 1> = { US: 0, Intl: 1 };
|
|
|
|
|
|
|
|
|
|
|
|
/** The playoff_matches columns the simulator actually reads. */
|
|
|
|
|
|
export type BracketMatch = Pick<
|
|
|
|
|
|
typeof schema.playoffMatches.$inferSelect,
|
|
|
|
|
|
"round" | "matchNumber" | "participant1Id" | "participant2Id" | "winnerId" | "loserId" | "isComplete"
|
|
|
|
|
|
>;
|
|
|
|
|
|
|
2026-04-08 16:52:10 -04:00
|
|
|
|
interface Team {
|
|
|
|
|
|
participantId: string;
|
|
|
|
|
|
side: Side;
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
/** Single-game strength on an Elo scale, decompressed from championship futures. */
|
|
|
|
|
|
elo: number;
|
2026-04-08 16:52:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface PlacementCounts {
|
|
|
|
|
|
champion: number;
|
|
|
|
|
|
finalist: number;
|
|
|
|
|
|
thirdPlace: number;
|
|
|
|
|
|
fourthPlace: number;
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
/** Lost the Elimination Final — the 5th–6th tier (1 per side per sim). */
|
|
|
|
|
|
elimFinalLoser: number;
|
|
|
|
|
|
/** Lost Elimination Round 4 — the 7th–8th tier (1 per side per sim). */
|
|
|
|
|
|
elimRound4Loser: number;
|
2026-04-08 16:52:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Plays one bracket game. `round`/`localMatch` identify the game within its side so a
|
|
|
|
|
|
* completed result can be looked up; `t1`/`t2` are the teams the simulation has
|
|
|
|
|
|
* routed into it.
|
|
|
|
|
|
*/
|
|
|
|
|
|
type PlayGame = (
|
|
|
|
|
|
round: string,
|
|
|
|
|
|
localMatch: number,
|
|
|
|
|
|
t1: Team,
|
|
|
|
|
|
t2: Team
|
|
|
|
|
|
) => { winner: Team; loser: Team };
|
|
|
|
|
|
|
|
|
|
|
|
interface LoadedBracket {
|
|
|
|
|
|
/** Each side's 10 teams in bracket slot order (8 opening-round, then 2 byes). */
|
|
|
|
|
|
slots: Record<Side, Team[]>;
|
|
|
|
|
|
/** All bracket matches, keyed by `${round}#${globalMatchNumber}`. */
|
|
|
|
|
|
matches: Map<string, BracketMatch>;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-08 16:52:10 -04:00
|
|
|
|
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
function zeroCounts(): PlacementCounts {
|
|
|
|
|
|
return {
|
|
|
|
|
|
champion: 0, finalist: 0, thirdPlace: 0, fourthPlace: 0,
|
|
|
|
|
|
elimFinalLoser: 0, elimRound4Loser: 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
function matchKey(round: string, matchNumber: number): string {
|
|
|
|
|
|
return `${round}#${matchNumber}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function simGame(t1: Team, t2: Team, parityFactor: number): { winner: Team; loser: Team } {
|
|
|
|
|
|
const p1Win = eloWinProbabilityWithParity(t1.elo, t2.elo, parityFactor);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
return Math.random() < p1Win ? { winner: t1, loser: t2 } : { winner: t2, loser: t1 };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Fisher-Yates shuffle (in-place).
|
|
|
|
|
|
*/
|
|
|
|
|
|
function shuffle<T>(arr: T[]): T[] {
|
|
|
|
|
|
for (let i = arr.length - 1; i > 0; i--) {
|
|
|
|
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
|
|
|
|
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
|
|
|
|
}
|
|
|
|
|
|
return arr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* The recorded loser of a completed match. loserId is written by the scoring flow,
|
|
|
|
|
|
* but fall back to "whichever slot isn't the winner" for older rows.
|
|
|
|
|
|
*/
|
|
|
|
|
|
function completedLoser(match: BracketMatch): string | null {
|
|
|
|
|
|
if (match.loserId) return match.loserId;
|
|
|
|
|
|
if (match.participant1Id === match.winnerId && match.participant2Id) return match.participant2Id;
|
|
|
|
|
|
if (match.participant2Id === match.winnerId && match.participant1Id) return match.participant1Id;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Build the game-playing function for one side.
|
|
|
|
|
|
*
|
|
|
|
|
|
* When the bracket has a completed result for a game AND that result is between the
|
|
|
|
|
|
* two teams the simulation routed into it, the recorded winner is used verbatim —
|
|
|
|
|
|
* that is what makes an already-played loss stick across all iterations. Anything
|
|
|
|
|
|
* else is simulated. The pair check keeps a corrupt or out-of-order row from
|
|
|
|
|
|
* desynchronising the rest of the bracket.
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function makePlayGame(
|
|
|
|
|
|
sideIndex: 0 | 1,
|
|
|
|
|
|
bracket: LoadedBracket | null,
|
|
|
|
|
|
parityFactor: number
|
|
|
|
|
|
): PlayGame {
|
|
|
|
|
|
if (!bracket) {
|
|
|
|
|
|
return (_round, _localMatch, t1, t2) => simGame(t1, t2, parityFactor);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (round, localMatch, t1, t2) => {
|
|
|
|
|
|
const match = bracket.matches.get(
|
|
|
|
|
|
matchKey(round, llwsMatchNumber(round, sideIndex, localMatch))
|
|
|
|
|
|
);
|
|
|
|
|
|
if (match?.isComplete && match.winnerId) {
|
|
|
|
|
|
const loserId = completedLoser(match);
|
|
|
|
|
|
const arrived = [t1.participantId, t2.participantId];
|
|
|
|
|
|
if (loserId && arrived.includes(match.winnerId) && arrived.includes(loserId)) {
|
|
|
|
|
|
return match.winnerId === t1.participantId
|
|
|
|
|
|
? { winner: t1, loser: t2 }
|
|
|
|
|
|
: { winner: t2, loser: t1 };
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return simGame(t1, t2, parityFactor);
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Play one of the two cross-side games (Consolation, World Championship). Both are a
|
|
|
|
|
|
* single shared match numbered 1, so they don't go through the side-local mapping.
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function playCrossoverGame(
|
|
|
|
|
|
round: string,
|
|
|
|
|
|
bracket: LoadedBracket | null,
|
|
|
|
|
|
parityFactor: number,
|
|
|
|
|
|
t1: Team,
|
|
|
|
|
|
t2: Team
|
|
|
|
|
|
): { winner: Team; loser: Team } {
|
|
|
|
|
|
const match = bracket?.matches.get(matchKey(round, 1));
|
|
|
|
|
|
if (match?.isComplete && match.winnerId) {
|
|
|
|
|
|
const loserId = completedLoser(match);
|
|
|
|
|
|
const arrived = [t1.participantId, t2.participantId];
|
|
|
|
|
|
if (loserId && arrived.includes(match.winnerId) && arrived.includes(loserId)) {
|
|
|
|
|
|
return match.winnerId === t1.participantId
|
|
|
|
|
|
? { winner: t1, loser: t2 }
|
|
|
|
|
|
: { winner: t2, loser: t1 };
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return simGame(t1, t2, parityFactor);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-08 16:52:10 -04:00
|
|
|
|
/**
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
* Simulate one side's 10-team double-elimination bracket.
|
|
|
|
|
|
*
|
|
|
|
|
|
* `slots` holds the side's teams in bracket order, matching the llws_20 participant
|
|
|
|
|
|
* layout: slots[0..7] are the four opening-round games (two teams each) and
|
|
|
|
|
|
* slots[8], slots[9] are the two bye teams entering Winners Round 2.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
*
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
* Structure (side-local, mirroring LLWS_ADVANCEMENT in lib/llws-bracket):
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
* Winners bracket
|
|
|
|
|
|
* OP1 s0 v s1 OP2 s2 v s3 OP3 s4 v s5 OP4 s6 v s7
|
|
|
|
|
|
* WR2-1 s8 v OP1w WR2-2 s9 v OP2w
|
|
|
|
|
|
* WSF1 OP3w v WR2-1w WSF2 WR2-2w v OP4w
|
|
|
|
|
|
* WF WSF1w v WSF2w → winner to the side championship
|
|
|
|
|
|
* Elimination bracket (a loss here is final)
|
|
|
|
|
|
* ER1-1 OP2l v OP3l ER1-2 OP1l v OP4l
|
|
|
|
|
|
* ER2-1 WR2-1l v ER1-1w ER2-2 WR2-2l v ER1-2w
|
|
|
|
|
|
* ER3-1 WSF1l v ER2-2w ER3-2 WSF2l v ER2-1w (cross-over)
|
|
|
|
|
|
* ER4 ER3-2w v ER3-1w → loser is the 7th–8th tier
|
|
|
|
|
|
* EF WFl v ER4w → loser is the 5th–6th tier
|
|
|
|
|
|
* Side championship: WFw v EFw → loser drops to the consolation game
|
2026-04-08 16:52:10 -04:00
|
|
|
|
*
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
* Note the double-chance path: the Winners Final loser is NOT out, it drops to the
|
|
|
|
|
|
* Elimination Final. There is no "if necessary" game, so the side championship is
|
|
|
|
|
|
* decided in one game.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
*
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
* The team order passed to `play` matches each match's participant1 / participant2
|
|
|
|
|
|
* slots in the generated bracket, so recorded results line up game for game.
|
|
|
|
|
|
*
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
* Returns { sideChampion, sideLoser }; the two scoring elimination losers are
|
|
|
|
|
|
* bumped into the counts directly.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
*/
|
|
|
|
|
|
function simulateSideBracket(
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
slots: Team[],
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
bump: (id: string, key: keyof PlacementCounts) => void,
|
|
|
|
|
|
play: PlayGame
|
2026-04-08 16:52:10 -04:00
|
|
|
|
): { sideChampion: Team; sideLoser: Team } {
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
// ── Winners bracket ────────────────────────────────────────────────────────
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const op1 = play("Opening Round", 1, slots[0], slots[1]);
|
|
|
|
|
|
const op2 = play("Opening Round", 2, slots[2], slots[3]);
|
|
|
|
|
|
const op3 = play("Opening Round", 3, slots[4], slots[5]);
|
|
|
|
|
|
const op4 = play("Opening Round", 4, slots[6], slots[7]);
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const wr21 = play("Winners Round 2", 1, slots[8], op1.winner);
|
|
|
|
|
|
const wr22 = play("Winners Round 2", 2, slots[9], op2.winner);
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const wsf1 = play("Winners Semifinals", 1, op3.winner, wr21.winner);
|
|
|
|
|
|
const wsf2 = play("Winners Semifinals", 2, wr22.winner, op4.winner);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const wf = play("Winners Final", 1, wsf1.winner, wsf2.winner);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
// ── Elimination bracket ────────────────────────────────────────────────────
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const er11 = play("Elimination Round 1", 1, op2.loser, op3.loser);
|
|
|
|
|
|
const er12 = play("Elimination Round 1", 2, op1.loser, op4.loser);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const er21 = play("Elimination Round 2", 1, wr21.loser, er11.winner);
|
|
|
|
|
|
const er22 = play("Elimination Round 2", 2, wr22.loser, er12.winner);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
// Cross-over: each semifinal loser meets the winner from the opposite half.
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const er31 = play("Elimination Round 3", 1, wsf1.loser, er22.winner);
|
|
|
|
|
|
const er32 = play("Elimination Round 3", 2, wsf2.loser, er21.winner);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const er4 = play("Elimination Round 4", 1, er32.winner, er31.winner);
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
bump(er4.loser.participantId, "elimRound4Loser"); // 7th–8th tier
|
|
|
|
|
|
|
|
|
|
|
|
// The Winners Final loser gets its second chance here.
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const ef = play("Elimination Final", 1, wf.loser, er4.winner);
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
bump(ef.loser.participantId, "elimFinalLoser"); // 5th–6th tier
|
|
|
|
|
|
|
|
|
|
|
|
// ── Side championship ──────────────────────────────────────────────────────
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const sideChampionship = play("Bracket Championship", 1, wf.winner, ef.winner);
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
|
|
|
|
|
|
return { sideChampion: sideChampionship.winner, sideLoser: sideChampionship.loser };
|
2026-04-08 16:52:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ─── Validation helpers ───────────────────────────────────────────────────────
|
|
|
|
|
|
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Parse a participant's externalId into a side.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The legacy pool-play suffixes ("US:A", "Intl:B", …) are still accepted so seasons
|
|
|
|
|
|
* configured before the format change keep loading; the pool part is ignored because
|
|
|
|
|
|
* the tournament no longer has pools.
|
|
|
|
|
|
*/
|
|
|
|
|
|
function parseExternalId(raw: string | null): { side: Side } | null {
|
2026-04-08 16:52:10 -04:00
|
|
|
|
if (!raw) return null;
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
const side = raw.toUpperCase().split(":")[0];
|
|
|
|
|
|
if (side === "US") return { side: "US" };
|
|
|
|
|
|
if (side === "INTL") return { side: "Intl" };
|
2026-04-08 16:52:10 -04:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-09 09:51:16 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Infer an externalId from a participant name when none is stored.
|
|
|
|
|
|
* Teams whose name is exactly "US" or starts with "US " (case-insensitive)
|
|
|
|
|
|
* are assigned to the US side; all others are assigned to Intl.
|
|
|
|
|
|
*/
|
|
|
|
|
|
function inferExternalIdFromName(name: string): string {
|
|
|
|
|
|
const upper = name.trim().toUpperCase();
|
|
|
|
|
|
return upper === "US" || upper.startsWith("US ") ? "US" : "Intl";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
// ─── Elo construction ─────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Map participants to single-game Elo ratings from their championship futures.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Teams with no odds entered sit at DEFAULT_ELO, which is also where every team lands
|
|
|
|
|
|
* when the season has no odds at all — so an unconfigured season still simulates as a
|
|
|
|
|
|
* field of coin flips rather than throwing.
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function buildLLWSElos(
|
|
|
|
|
|
evRows: Array<{ participantId: string; sourceOdds: number | null }>
|
|
|
|
|
|
): Map<string, number> {
|
|
|
|
|
|
const oddsInput = evRows
|
|
|
|
|
|
.filter((row) => row.sourceOdds !== null)
|
|
|
|
|
|
.map((row) => ({ participantId: row.participantId, odds: row.sourceOdds ?? 0 }));
|
|
|
|
|
|
|
|
|
|
|
|
// convertFuturesToElo needs a spread to normalise against; a single priced team
|
|
|
|
|
|
// carries no information about the rest of the field.
|
|
|
|
|
|
if (oddsInput.length < 2) return new Map();
|
|
|
|
|
|
return convertFuturesToElo(oddsInput);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ─── Bracket loading ──────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Read the seeded llws_20 bracket for this season, if there is one.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Returns null when no bracket exists yet or its opening slots have not been filled
|
|
|
|
|
|
* in — in that case the caller falls back to a randomized draw. Throws when the
|
|
|
|
|
|
* bracket is seeded with participants that don't belong to the season, which is a
|
|
|
|
|
|
* misconfiguration worth surfacing rather than silently ignoring.
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function readBracketSlots(
|
|
|
|
|
|
matches: BracketMatch[],
|
|
|
|
|
|
teamsById: Map<string, Team>
|
|
|
|
|
|
): LoadedBracket | null {
|
|
|
|
|
|
if (matches.length === 0) return null;
|
|
|
|
|
|
|
|
|
|
|
|
const byKey = new Map(matches.map((m) => [matchKey(m.round, m.matchNumber), m]));
|
|
|
|
|
|
const slots: Record<Side, Team[]> = { US: [], Intl: [] };
|
|
|
|
|
|
const seen = new Set<string>();
|
|
|
|
|
|
|
|
|
|
|
|
for (const side of ["US", "Intl"] as const) {
|
|
|
|
|
|
const sideIndex = SIDE_INDEX[side];
|
|
|
|
|
|
const ids: (string | null)[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (let local = 1; local <= 4; local++) {
|
|
|
|
|
|
const match = byKey.get(
|
|
|
|
|
|
matchKey("Opening Round", llwsMatchNumber("Opening Round", sideIndex, local))
|
|
|
|
|
|
);
|
|
|
|
|
|
ids.push(match?.participant1Id ?? null, match?.participant2Id ?? null);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (let local = 1; local <= 2; local++) {
|
|
|
|
|
|
const match = byKey.get(
|
|
|
|
|
|
matchKey("Winners Round 2", llwsMatchNumber("Winners Round 2", sideIndex, local))
|
|
|
|
|
|
);
|
|
|
|
|
|
ids.push(match?.participant1Id ?? null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// An unseeded (or partially seeded) bracket carries no draw information.
|
|
|
|
|
|
if (ids.some((id) => id === null)) return null;
|
|
|
|
|
|
|
|
|
|
|
|
for (const id of ids) {
|
|
|
|
|
|
if (seen.has(id as string)) {
|
|
|
|
|
|
throw new Error(`LLWS bracket seeds participant ${id} into more than one slot.`);
|
|
|
|
|
|
}
|
|
|
|
|
|
seen.add(id as string);
|
|
|
|
|
|
|
|
|
|
|
|
const team = teamsById.get(id as string);
|
|
|
|
|
|
if (!team) {
|
|
|
|
|
|
throw new Error(
|
|
|
|
|
|
`LLWS bracket references participant ${id}, which is not in this sports season.`
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
// The bracket is authoritative about which side a team is on.
|
|
|
|
|
|
slots[side].push({ ...team, side });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return { slots, matches: byKey };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-08 16:52:10 -04:00
|
|
|
|
// ─── Simulator ────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
export class LLWSSimulator implements Simulator {
|
Fix MLB standings 406 error and refactor ESPN adapter shared code (#62)
## Summary
- **Root cause**: `statsapi.mlb.com` returns 406 (deprecated). Switched MLB to ESPN's free standings API (`site.api.espn.com/apis/v2/sports/baseball/mlb/standings`), consistent with NBA, WNBA, and MLS.
- **Refactor**: Extracted a shared `espn.ts` utility module, eliminating 4× duplication of `statsMap()`, `flattenEspnStandings()`, ESPN interfaces, and the `playoffSeed` → conference rank logic across adapters.
- **Bug fixes** found during review and applied across all affected adapters:
- `parseConferenceRank`: `|| undefined` falsy-zero bug replaced with `isNaN` guard
- Sort comparators: stable alphabetical tiebreaker added to MLB, NBA, WNBA
- `winPct`: falls back to `wins/(wins+losses)` if ESPN omits the stat (was silently 0)
- statsMap pre-built once per entry before sorting in all adapters (was rebuilt per comparison)
- WNBA `parseEntry`: accepts pre-computed `sm` instead of rebuilding it internally
- MLB `gamesBack`: tests updated to reflect ESPN returns numeric `0` for division leaders (old API used `"-"` → `undefined`)
## Test plan
- [ ] All 60 standings-sync unit tests pass (`npm run test:run -- app/services/standings-sync`)
- [ ] Trigger MLB standings sync from admin panel and confirm it returns data without a 406
- [ ] Confirm NBA, WNBA, MLS syncs still work (adapters touched but behaviour unchanged)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com>
Reviewed-on: https://forge.brackt.com/chrisp/brackt/pulls/62
2026-06-01 03:31:18 +00:00
|
|
|
|
constructor(private numSimulations = NUM_SIMULATIONS) {}
|
|
|
|
|
|
|
2026-06-30 23:24:48 +00:00
|
|
|
|
async simulate(sportsSeasonId: string, config: Record<string, unknown> = {}): Promise<SimulationResult[]> {
|
|
|
|
|
|
const numSimulations = Math.round(positiveConfigNumber(config, "iterations", this.numSimulations));
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const parityFactor = positiveConfigNumber(config, "parityFactor", LLWS_PARITY_FACTOR);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
const db = database();
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Load all participants.
|
|
|
|
|
|
const participants = await db
|
Canonical tournament layer: schema + backfill (1/2) (#365)
* refactor(schema): rename per-window tables to season_* prefix
Renames participants, participant_expected_values, participant_qualifying_totals,
participant_results, participant_surface_elos to season_* prefixed names.
Renames event_results.participant_id to season_participant_id.
Phase 1a of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor: rename participant.ts model file to season-participant.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(models): update model layer to use renamed schema exports
Updated all model files to use the renamed schema exports from Task 1:
- participants → seasonParticipants
- participantExpectedValues → seasonParticipantExpectedValues
- participantQualifyingTotals → seasonParticipantQualifyingTotals
- participantResults → seasonParticipantResults
- participantSurfaceElos → seasonParticipantSurfaceElos
- eventResults.participantId → eventResults.seasonParticipantId
- db.query relation accessors updated
- Relation field .participant → .seasonParticipant where applicable
- Import paths updated: ./participant → ./season-participant
Files updated (14 model files + 3 test files):
- draft-pick.ts
- draft-utils.ts
- event-result.ts
- group-stage-match.ts
- participant-result.ts
- qualifying-points.ts
- scoring-calculator.ts
- scoring-event.ts
- sports-season.ts
- surface-elo.ts
- team-score-events.ts
- cs2-major-stage.ts
- golf-skills.ts
- participant-expected-value.ts
- __tests__/sports-season.clone.test.ts
- __tests__/auto-pick.test.ts
- __tests__/executeAutoPick.timer.test.ts
Typecheck errors decreased: 779 → 499 (280 fewer)
All model file errors related to renamed schemas resolved.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(routes): update route layer to use renamed schema exports
- Update model import from ~/models/participant to ~/models/season-participant
- Rename schema.participants to schema.seasonParticipants
- Rename schema.participantResults to schema.seasonParticipantResults
- Rename db.query.participants to db.query.seasonParticipants
- Update 9 route files and 1 test file
Affected files:
- admin.sports-seasons.$id.events.$eventId.bracket.server.ts
- admin.sports-seasons.$id.participants.tsx
- api/draft.force-manual-pick.ts
- api/draft.make-pick.ts
- api/draft.replace-pick.ts
- api/seasons.$seasonId.draft.ts
- leagues/$leagueId.draft-board.$seasonId.tsx
- leagues/$leagueId.sports-seasons.$sportsSeasonId.server.ts
- admin/__tests__/sports-seasons-participants.test.ts
Error count reduced from 499 to 453 (46 errors fixed).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(routes): update route files for schema rename
Update route imports from ~/models/participant to ~/models/season-participant
and fix references to .participant/.participantId on event results to use
.seasonParticipant/.seasonParticipantId after schema rename.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(services): update simulators and services for renamed schema
Update all simulators, services, and server files to use renamed schema tables:
- participants → seasonParticipants
- participantExpectedValues → seasonParticipantExpectedValues
- participantResults → seasonParticipantResults
- eventResults.participantId → eventResults.seasonParticipantId
Files updated:
- 20 sport simulators (NBA, NHL, NFL, MLB, etc.)
- probability-updater.ts
- standings-sync/index.ts
- sports-data-sync.server.ts
- server/socket.ts
Typecheck errors reduced from 365 to 0.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* migration: rename per-window tables to season_* prefix
* fix(tests): update mock query keys after participants table rename
Change mock db.query.participants to db.query.seasonParticipants in test
files to match the schema rename from commit 66145a9. This fixes
"Cannot read properties of undefined (reading 'findFirst'/'findMany')"
errors that occurred when production code queries db.query.seasonParticipants
but test mocks only defined the old participants key.
Files updated:
- app/services/simulations/__tests__/world-cup-simulator.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.timer-mode.test.ts
- app/routes/api/__tests__/draft.make-pick.timer-mode.test.ts
- server/__tests__/timer-autodraft.test.ts
- app/models/__tests__/team-score-events.test.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(tests): update remaining mock paths and keys after schema rename
* fix(tests): final two mock stragglers after schema rename
- draft-pick.test.ts: assertion on db.query.participantQualifyingTotals
- process-match-result.test.ts: mock key participants → seasonParticipants
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* chore: add post-phase1a baseline capture (temp, for diff verification)
* chore: capture pre-migration baselines
* chore: remove post-phase1a capture helper after verification
* schema: add canonical tournament & participant tables
Adds tournaments, participants (canonical), tournament_results, and
participant_surface_elos (canonical). Adds nullable tournament_id to
scoring_events and nullable participant_id to season_participants.
Phase 1b of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* feat(models): add canonical tournament, participant, result, surface-elo models
Adds CRUD modules for the canonical tables created in commit 775b905.
Each module mirrors existing app/models conventions (database() from
~/database/context, schema from ~/database/schema, mock-based tests).
Key implementation notes:
- participant.ts exports use "Canonical" prefix (CanonicalParticipant,
createCanonicalParticipant, etc.) to avoid collision with existing
season-participant.ts exports
- All four models include comprehensive unit tests following the
audit-log.test.ts pattern
- Tests use mocked db responses (no real database access)
- Upsert functions use onConflictDoUpdate for appropriate unique constraints
Part of Phase 1b of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* migration: create canonical tables, add nullable FKs
* scripts: add extractTournamentIdentity helper for backfill
Pure function that derives canonical (name, year) identity from a
scoring_events row, stripping trailing 4-digit years from the name or
falling back to eventDate. Used by the Phase 2 backfill to group
per-window events into canonical tournaments.
* scripts: add backfill orchestrator for canonical layer
Populates canonical tournaments, participants, tournament_results, and
participant_surface_elos from per-window data for qualifying-points
sports. Skips already-linked rows, is idempotent, and supports dry-run
mode.
Critical invariants enforced by the implementation:
- qualifying_points_awarded is never copied to tournament_results
- season_participant_qualifying_totals is never touched
- conflicting surface-Elo values between windows raise a loud error
(recorded in report.errors) rather than overwriting
* scripts: add backfill CLI with dry-run default
Wires backfill-canonical-layer.ts to a CLI entry point exposed as
`npm run backfill:canonical`. Defaults to --dry-run; requires --apply
to actually write. Supports --sport=<uuid> to limit to a single sport.
Exits 2 if the backfill reports errors (e.g., surface-Elo conflicts).
* fix(backfill-cli): wrap runBackfill in DatabaseContext.run
The orchestrator uses database() from ~/database/context, which requires
AsyncLocalStorage to be populated. Wrap the CLI invocation with
DatabaseContext.run(db, ...) using server/db's cached connection pool.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(backfill-cli): exit 0 on success so pg pool doesn't block
The cached postgres connection pool keeps the Node event loop open after
main() returns. Explicit process.exit(0) on success mirrors the pattern
in scripts/capture-baseline.ts.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Chris Parsons <chrisp@extrahop.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-01 20:13:18 -07:00
|
|
|
|
.select({ id: schema.seasonParticipants.id, name: schema.seasonParticipants.name, externalId: schema.seasonParticipants.externalId })
|
|
|
|
|
|
.from(schema.seasonParticipants)
|
|
|
|
|
|
.where(eq(schema.seasonParticipants.sportsSeasonId, sportsSeasonId));
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
|
|
|
|
|
if (participants.length !== US_TEAM_COUNT + INTL_TEAM_COUNT) {
|
|
|
|
|
|
throw new Error(
|
|
|
|
|
|
`LLWS simulator requires exactly ${US_TEAM_COUNT + INTL_TEAM_COUNT} participants, ` +
|
|
|
|
|
|
`found ${participants.length}.`
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Load championship futures odds.
|
|
|
|
|
|
const evRows = await db
|
|
|
|
|
|
.select({
|
Canonical tournament layer: schema + backfill (1/2) (#365)
* refactor(schema): rename per-window tables to season_* prefix
Renames participants, participant_expected_values, participant_qualifying_totals,
participant_results, participant_surface_elos to season_* prefixed names.
Renames event_results.participant_id to season_participant_id.
Phase 1a of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor: rename participant.ts model file to season-participant.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(models): update model layer to use renamed schema exports
Updated all model files to use the renamed schema exports from Task 1:
- participants → seasonParticipants
- participantExpectedValues → seasonParticipantExpectedValues
- participantQualifyingTotals → seasonParticipantQualifyingTotals
- participantResults → seasonParticipantResults
- participantSurfaceElos → seasonParticipantSurfaceElos
- eventResults.participantId → eventResults.seasonParticipantId
- db.query relation accessors updated
- Relation field .participant → .seasonParticipant where applicable
- Import paths updated: ./participant → ./season-participant
Files updated (14 model files + 3 test files):
- draft-pick.ts
- draft-utils.ts
- event-result.ts
- group-stage-match.ts
- participant-result.ts
- qualifying-points.ts
- scoring-calculator.ts
- scoring-event.ts
- sports-season.ts
- surface-elo.ts
- team-score-events.ts
- cs2-major-stage.ts
- golf-skills.ts
- participant-expected-value.ts
- __tests__/sports-season.clone.test.ts
- __tests__/auto-pick.test.ts
- __tests__/executeAutoPick.timer.test.ts
Typecheck errors decreased: 779 → 499 (280 fewer)
All model file errors related to renamed schemas resolved.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(routes): update route layer to use renamed schema exports
- Update model import from ~/models/participant to ~/models/season-participant
- Rename schema.participants to schema.seasonParticipants
- Rename schema.participantResults to schema.seasonParticipantResults
- Rename db.query.participants to db.query.seasonParticipants
- Update 9 route files and 1 test file
Affected files:
- admin.sports-seasons.$id.events.$eventId.bracket.server.ts
- admin.sports-seasons.$id.participants.tsx
- api/draft.force-manual-pick.ts
- api/draft.make-pick.ts
- api/draft.replace-pick.ts
- api/seasons.$seasonId.draft.ts
- leagues/$leagueId.draft-board.$seasonId.tsx
- leagues/$leagueId.sports-seasons.$sportsSeasonId.server.ts
- admin/__tests__/sports-seasons-participants.test.ts
Error count reduced from 499 to 453 (46 errors fixed).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(routes): update route files for schema rename
Update route imports from ~/models/participant to ~/models/season-participant
and fix references to .participant/.participantId on event results to use
.seasonParticipant/.seasonParticipantId after schema rename.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(services): update simulators and services for renamed schema
Update all simulators, services, and server files to use renamed schema tables:
- participants → seasonParticipants
- participantExpectedValues → seasonParticipantExpectedValues
- participantResults → seasonParticipantResults
- eventResults.participantId → eventResults.seasonParticipantId
Files updated:
- 20 sport simulators (NBA, NHL, NFL, MLB, etc.)
- probability-updater.ts
- standings-sync/index.ts
- sports-data-sync.server.ts
- server/socket.ts
Typecheck errors reduced from 365 to 0.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* migration: rename per-window tables to season_* prefix
* fix(tests): update mock query keys after participants table rename
Change mock db.query.participants to db.query.seasonParticipants in test
files to match the schema rename from commit 66145a9. This fixes
"Cannot read properties of undefined (reading 'findFirst'/'findMany')"
errors that occurred when production code queries db.query.seasonParticipants
but test mocks only defined the old participants key.
Files updated:
- app/services/simulations/__tests__/world-cup-simulator.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.timer-mode.test.ts
- app/routes/api/__tests__/draft.make-pick.timer-mode.test.ts
- server/__tests__/timer-autodraft.test.ts
- app/models/__tests__/team-score-events.test.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(tests): update remaining mock paths and keys after schema rename
* fix(tests): final two mock stragglers after schema rename
- draft-pick.test.ts: assertion on db.query.participantQualifyingTotals
- process-match-result.test.ts: mock key participants → seasonParticipants
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* chore: add post-phase1a baseline capture (temp, for diff verification)
* chore: capture pre-migration baselines
* chore: remove post-phase1a capture helper after verification
* schema: add canonical tournament & participant tables
Adds tournaments, participants (canonical), tournament_results, and
participant_surface_elos (canonical). Adds nullable tournament_id to
scoring_events and nullable participant_id to season_participants.
Phase 1b of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* feat(models): add canonical tournament, participant, result, surface-elo models
Adds CRUD modules for the canonical tables created in commit 775b905.
Each module mirrors existing app/models conventions (database() from
~/database/context, schema from ~/database/schema, mock-based tests).
Key implementation notes:
- participant.ts exports use "Canonical" prefix (CanonicalParticipant,
createCanonicalParticipant, etc.) to avoid collision with existing
season-participant.ts exports
- All four models include comprehensive unit tests following the
audit-log.test.ts pattern
- Tests use mocked db responses (no real database access)
- Upsert functions use onConflictDoUpdate for appropriate unique constraints
Part of Phase 1b of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* migration: create canonical tables, add nullable FKs
* scripts: add extractTournamentIdentity helper for backfill
Pure function that derives canonical (name, year) identity from a
scoring_events row, stripping trailing 4-digit years from the name or
falling back to eventDate. Used by the Phase 2 backfill to group
per-window events into canonical tournaments.
* scripts: add backfill orchestrator for canonical layer
Populates canonical tournaments, participants, tournament_results, and
participant_surface_elos from per-window data for qualifying-points
sports. Skips already-linked rows, is idempotent, and supports dry-run
mode.
Critical invariants enforced by the implementation:
- qualifying_points_awarded is never copied to tournament_results
- season_participant_qualifying_totals is never touched
- conflicting surface-Elo values between windows raise a loud error
(recorded in report.errors) rather than overwriting
* scripts: add backfill CLI with dry-run default
Wires backfill-canonical-layer.ts to a CLI entry point exposed as
`npm run backfill:canonical`. Defaults to --dry-run; requires --apply
to actually write. Supports --sport=<uuid> to limit to a single sport.
Exits 2 if the backfill reports errors (e.g., surface-Elo conflicts).
* fix(backfill-cli): wrap runBackfill in DatabaseContext.run
The orchestrator uses database() from ~/database/context, which requires
AsyncLocalStorage to be populated. Wrap the CLI invocation with
DatabaseContext.run(db, ...) using server/db's cached connection pool.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(backfill-cli): exit 0 on success so pg pool doesn't block
The cached postgres connection pool keeps the Node event loop open after
main() returns. Explicit process.exit(0) on success mirrors the pattern
in scripts/capture-baseline.ts.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Chris Parsons <chrisp@extrahop.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-01 20:13:18 -07:00
|
|
|
|
participantId: schema.seasonParticipantExpectedValues.participantId,
|
|
|
|
|
|
sourceOdds: schema.seasonParticipantExpectedValues.sourceOdds,
|
2026-04-08 16:52:10 -04:00
|
|
|
|
})
|
Canonical tournament layer: schema + backfill (1/2) (#365)
* refactor(schema): rename per-window tables to season_* prefix
Renames participants, participant_expected_values, participant_qualifying_totals,
participant_results, participant_surface_elos to season_* prefixed names.
Renames event_results.participant_id to season_participant_id.
Phase 1a of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor: rename participant.ts model file to season-participant.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(models): update model layer to use renamed schema exports
Updated all model files to use the renamed schema exports from Task 1:
- participants → seasonParticipants
- participantExpectedValues → seasonParticipantExpectedValues
- participantQualifyingTotals → seasonParticipantQualifyingTotals
- participantResults → seasonParticipantResults
- participantSurfaceElos → seasonParticipantSurfaceElos
- eventResults.participantId → eventResults.seasonParticipantId
- db.query relation accessors updated
- Relation field .participant → .seasonParticipant where applicable
- Import paths updated: ./participant → ./season-participant
Files updated (14 model files + 3 test files):
- draft-pick.ts
- draft-utils.ts
- event-result.ts
- group-stage-match.ts
- participant-result.ts
- qualifying-points.ts
- scoring-calculator.ts
- scoring-event.ts
- sports-season.ts
- surface-elo.ts
- team-score-events.ts
- cs2-major-stage.ts
- golf-skills.ts
- participant-expected-value.ts
- __tests__/sports-season.clone.test.ts
- __tests__/auto-pick.test.ts
- __tests__/executeAutoPick.timer.test.ts
Typecheck errors decreased: 779 → 499 (280 fewer)
All model file errors related to renamed schemas resolved.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(routes): update route layer to use renamed schema exports
- Update model import from ~/models/participant to ~/models/season-participant
- Rename schema.participants to schema.seasonParticipants
- Rename schema.participantResults to schema.seasonParticipantResults
- Rename db.query.participants to db.query.seasonParticipants
- Update 9 route files and 1 test file
Affected files:
- admin.sports-seasons.$id.events.$eventId.bracket.server.ts
- admin.sports-seasons.$id.participants.tsx
- api/draft.force-manual-pick.ts
- api/draft.make-pick.ts
- api/draft.replace-pick.ts
- api/seasons.$seasonId.draft.ts
- leagues/$leagueId.draft-board.$seasonId.tsx
- leagues/$leagueId.sports-seasons.$sportsSeasonId.server.ts
- admin/__tests__/sports-seasons-participants.test.ts
Error count reduced from 499 to 453 (46 errors fixed).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(routes): update route files for schema rename
Update route imports from ~/models/participant to ~/models/season-participant
and fix references to .participant/.participantId on event results to use
.seasonParticipant/.seasonParticipantId after schema rename.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(services): update simulators and services for renamed schema
Update all simulators, services, and server files to use renamed schema tables:
- participants → seasonParticipants
- participantExpectedValues → seasonParticipantExpectedValues
- participantResults → seasonParticipantResults
- eventResults.participantId → eventResults.seasonParticipantId
Files updated:
- 20 sport simulators (NBA, NHL, NFL, MLB, etc.)
- probability-updater.ts
- standings-sync/index.ts
- sports-data-sync.server.ts
- server/socket.ts
Typecheck errors reduced from 365 to 0.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* migration: rename per-window tables to season_* prefix
* fix(tests): update mock query keys after participants table rename
Change mock db.query.participants to db.query.seasonParticipants in test
files to match the schema rename from commit 66145a9. This fixes
"Cannot read properties of undefined (reading 'findFirst'/'findMany')"
errors that occurred when production code queries db.query.seasonParticipants
but test mocks only defined the old participants key.
Files updated:
- app/services/simulations/__tests__/world-cup-simulator.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.timer-mode.test.ts
- app/routes/api/__tests__/draft.make-pick.timer-mode.test.ts
- server/__tests__/timer-autodraft.test.ts
- app/models/__tests__/team-score-events.test.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(tests): update remaining mock paths and keys after schema rename
* fix(tests): final two mock stragglers after schema rename
- draft-pick.test.ts: assertion on db.query.participantQualifyingTotals
- process-match-result.test.ts: mock key participants → seasonParticipants
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* chore: add post-phase1a baseline capture (temp, for diff verification)
* chore: capture pre-migration baselines
* chore: remove post-phase1a capture helper after verification
* schema: add canonical tournament & participant tables
Adds tournaments, participants (canonical), tournament_results, and
participant_surface_elos (canonical). Adds nullable tournament_id to
scoring_events and nullable participant_id to season_participants.
Phase 1b of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* feat(models): add canonical tournament, participant, result, surface-elo models
Adds CRUD modules for the canonical tables created in commit 775b905.
Each module mirrors existing app/models conventions (database() from
~/database/context, schema from ~/database/schema, mock-based tests).
Key implementation notes:
- participant.ts exports use "Canonical" prefix (CanonicalParticipant,
createCanonicalParticipant, etc.) to avoid collision with existing
season-participant.ts exports
- All four models include comprehensive unit tests following the
audit-log.test.ts pattern
- Tests use mocked db responses (no real database access)
- Upsert functions use onConflictDoUpdate for appropriate unique constraints
Part of Phase 1b of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* migration: create canonical tables, add nullable FKs
* scripts: add extractTournamentIdentity helper for backfill
Pure function that derives canonical (name, year) identity from a
scoring_events row, stripping trailing 4-digit years from the name or
falling back to eventDate. Used by the Phase 2 backfill to group
per-window events into canonical tournaments.
* scripts: add backfill orchestrator for canonical layer
Populates canonical tournaments, participants, tournament_results, and
participant_surface_elos from per-window data for qualifying-points
sports. Skips already-linked rows, is idempotent, and supports dry-run
mode.
Critical invariants enforced by the implementation:
- qualifying_points_awarded is never copied to tournament_results
- season_participant_qualifying_totals is never touched
- conflicting surface-Elo values between windows raise a loud error
(recorded in report.errors) rather than overwriting
* scripts: add backfill CLI with dry-run default
Wires backfill-canonical-layer.ts to a CLI entry point exposed as
`npm run backfill:canonical`. Defaults to --dry-run; requires --apply
to actually write. Supports --sport=<uuid> to limit to a single sport.
Exits 2 if the backfill reports errors (e.g., surface-Elo conflicts).
* fix(backfill-cli): wrap runBackfill in DatabaseContext.run
The orchestrator uses database() from ~/database/context, which requires
AsyncLocalStorage to be populated. Wrap the CLI invocation with
DatabaseContext.run(db, ...) using server/db's cached connection pool.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(backfill-cli): exit 0 on success so pg pool doesn't block
The cached postgres connection pool keeps the Node event loop open after
main() returns. Explicit process.exit(0) on success mirrors the pattern
in scripts/capture-baseline.ts.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Chris Parsons <chrisp@extrahop.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-01 20:13:18 -07:00
|
|
|
|
.from(schema.seasonParticipantExpectedValues)
|
|
|
|
|
|
.where(eq(schema.seasonParticipantExpectedValues.sportsSeasonId, sportsSeasonId));
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
// 3. Decompress the futures into single-game Elo ratings.
|
|
|
|
|
|
const eloMap = buildLLWSElos(evRows);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
// 4. Parse externalId for each participant to determine which side they're on.
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
// A seeded bracket overrides this below, but the field still has to be a legal
|
|
|
|
|
|
// 10/10 split before we know whether a bracket exists.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
const teams: Team[] = [];
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const unparseableSides: Array<{ id: string; externalId: string | null }> = [];
|
2026-04-08 16:52:10 -04:00
|
|
|
|
for (const p of participants) {
|
2026-04-09 09:51:16 -04:00
|
|
|
|
const raw = p.externalId ?? inferExternalIdFromName(p.name);
|
|
|
|
|
|
const parsed = parseExternalId(raw);
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
if (!parsed) unparseableSides.push({ id: p.id, externalId: p.externalId });
|
2026-04-08 16:52:10 -04:00
|
|
|
|
teams.push({
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
// Provisional: a seeded bracket overwrites this below.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
participantId: p.id,
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
side: parsed?.side ?? "Intl",
|
|
|
|
|
|
elo: eloMap.get(p.id) ?? DEFAULT_ELO,
|
2026-04-08 16:52:10 -04:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const teamsById = new Map(teams.map((t) => [t.participantId, t]));
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
// 5. Load the real bracket (draw + results so far), if one has been generated.
|
|
|
|
|
|
const bracketEvent = await db.query.scoringEvents.findFirst({
|
|
|
|
|
|
where: and(
|
|
|
|
|
|
eq(schema.scoringEvents.sportsSeasonId, sportsSeasonId),
|
|
|
|
|
|
eq(schema.scoringEvents.eventType, "playoff_game"),
|
|
|
|
|
|
eq(schema.scoringEvents.bracketTemplateId, LLWS_TEMPLATE_ID)
|
|
|
|
|
|
),
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const bracketMatches = bracketEvent
|
|
|
|
|
|
? await db.query.playoffMatches.findMany({
|
|
|
|
|
|
where: eq(schema.playoffMatches.scoringEventId, bracketEvent.id),
|
|
|
|
|
|
})
|
|
|
|
|
|
: [];
|
|
|
|
|
|
|
|
|
|
|
|
const bracket = readBracketSlots(bracketMatches, teamsById);
|
|
|
|
|
|
|
|
|
|
|
|
// Validate sides. A seeded bracket already fixes the draw and an even 10/10 split,
|
|
|
|
|
|
// so externalId only has to be usable on the randomized pre-bracket path.
|
|
|
|
|
|
if (!bracket) {
|
|
|
|
|
|
const [firstBad] = unparseableSides;
|
|
|
|
|
|
if (firstBad) {
|
|
|
|
|
|
throw new Error(
|
|
|
|
|
|
`Participant ${firstBad.id} has invalid externalId "${firstBad.externalId}". ` +
|
|
|
|
|
|
`Expected: "US" or "Intl".`
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const usTeams = teams.filter((t) => t.side === "US");
|
|
|
|
|
|
const intlTeams = teams.filter((t) => t.side === "Intl");
|
|
|
|
|
|
|
|
|
|
|
|
if (usTeams.length !== US_TEAM_COUNT) {
|
|
|
|
|
|
throw new Error(`Expected ${US_TEAM_COUNT} US teams, found ${usTeams.length}.`);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (intlTeams.length !== INTL_TEAM_COUNT) {
|
|
|
|
|
|
throw new Error(`Expected ${INTL_TEAM_COUNT} International teams, found ${intlTeams.length}.`);
|
|
|
|
|
|
}
|
2026-04-08 16:52:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const usPool = bracket ? bracket.slots.US : teams.filter((t) => t.side === "US");
|
|
|
|
|
|
const intlPool = bracket ? bracket.slots.Intl : teams.filter((t) => t.side === "Intl");
|
|
|
|
|
|
|
|
|
|
|
|
const playUS = makePlayGame(SIDE_INDEX.US, bracket, parityFactor);
|
|
|
|
|
|
const playIntl = makePlayGame(SIDE_INDEX.Intl, bracket, parityFactor);
|
|
|
|
|
|
|
|
|
|
|
|
// 6. Initialise placement count accumulators for all participants.
|
2026-04-08 16:52:10 -04:00
|
|
|
|
const allIds = participants.map((p) => p.id);
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
const counts = new Map<string, PlacementCounts>(allIds.map((id) => [id, zeroCounts()]));
|
2026-04-08 16:52:10 -04:00
|
|
|
|
const bump = (id: string, key: keyof PlacementCounts) => {
|
|
|
|
|
|
const entry = counts.get(id);
|
|
|
|
|
|
if (entry) entry[key]++;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
// 7. Run Monte Carlo simulations.
|
2026-06-30 23:24:48 +00:00
|
|
|
|
for (let s = 0; s < numSimulations; s++) {
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
// With a real bracket the draw is fixed; without one it is modelled as random.
|
|
|
|
|
|
const usSlots = bracket ? usPool : shuffle([...usPool]);
|
|
|
|
|
|
const intlSlots = bracket ? intlPool : shuffle([...intlPool]);
|
|
|
|
|
|
|
2026-04-08 16:52:10 -04:00
|
|
|
|
const { sideChampion: usChamp, sideLoser: usLose } =
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
simulateSideBracket(usSlots, bump, playUS);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
const { sideChampion: intlChamp, sideLoser: intlLose } =
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
simulateSideBracket(intlSlots, bump, playIntl);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
|
|
|
|
|
// Consolation game: 3rd / 4th place.
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const consolation = playCrossoverGame(
|
|
|
|
|
|
"Consolation Third Place", bracket, parityFactor, usLose, intlLose
|
|
|
|
|
|
);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
bump(consolation.winner.participantId, "thirdPlace");
|
|
|
|
|
|
bump(consolation.loser.participantId, "fourthPlace");
|
|
|
|
|
|
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
// World Championship: 1st / 2nd place.
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
const ws = playCrossoverGame(
|
|
|
|
|
|
"World Championship", bracket, parityFactor, usChamp, intlChamp
|
|
|
|
|
|
);
|
2026-04-08 16:52:10 -04:00
|
|
|
|
bump(ws.winner.participantId, "champion");
|
|
|
|
|
|
bump(ws.loser.participantId, "finalist");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Make LLWS simulator bracket-aware and calibrate its futures model
The LLWS simulator was overestimating favorites and ignoring games that had
already been played. Two separate causes:
1. Championship futures were used directly as single-game strength
(p1 / (p1 + p2)). A future already compounds the ~6 wins needed to take
the title, so this made every individual game as lopsided as the whole
tournament and re-compounded that edge round after round. Against a
representative 20-team board the favorite priced at 21.8% simulated at
44.9%, and the longest shot fell to ~0%.
Futures are now decompressed to single-game Elo via convertFuturesToElo,
the same pipeline the other bracket simulators use, and games are played
with eloWinProbabilityWithParity. The parity factor was calibrated by
sweeping it until a randomized-draw simulation reproduces the board it
was fed: at 1000 the favorite simulates at 21.8% and field-wide RMSE
drops from 0.062 to 0.003. It is overridable per season via config.
2. The simulator never read playoff_matches, so it re-ran the tournament
from an empty bracket every time and shuffled the draw at random each
iteration. A recorded loss changed nothing.
It now loads the seeded llws_20 bracket, places teams in their real
slots, and replays completed games from their recorded result instead of
re-simulating them, so an eliminated team correctly drops to zero. When
no bracket exists (or it has no participants seeded) it falls back to the
previous randomized-draw behavior, and a seeded bracket is authoritative
about which side a team is on, so externalId is only required on the
pre-bracket path.
Guards: a recorded result is only honored when its two participants are the
ones the simulation routed into that game, so a corrupt or out-of-order row
cannot desynchronize the rest of the bracket; brackets seeding an unknown or
duplicated participant now fail loudly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5vQZMPeokzfMqHQjq1RDZ
2026-08-21 21:09:47 +00:00
|
|
|
|
// 8. Convert counts to probability distributions.
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
// Each of the two 5–8 tiers takes exactly 2 teams per sim (one per side), and
|
|
|
|
|
|
// the teams within a tier are tied, so the tier probability is split across
|
|
|
|
|
|
// its two positions.
|
|
|
|
|
|
const tierDivisor = 2 * numSimulations;
|
2026-04-08 16:52:10 -04:00
|
|
|
|
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
const empty = zeroCounts();
|
2026-04-08 16:52:10 -04:00
|
|
|
|
return allIds.map((id) => {
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
const c = counts.get(id) ?? empty;
|
|
|
|
|
|
const upperTier = c.elimFinalLoser / tierDivisor; // 5th–6th
|
|
|
|
|
|
const lowerTier = c.elimRound4Loser / tierDivisor; // 7th–8th
|
2026-04-08 16:52:10 -04:00
|
|
|
|
return {
|
|
|
|
|
|
participantId: id,
|
|
|
|
|
|
probabilities: {
|
2026-06-30 23:24:48 +00:00
|
|
|
|
probFirst: c.champion / numSimulations,
|
|
|
|
|
|
probSecond: c.finalist / numSimulations,
|
|
|
|
|
|
probThird: c.thirdPlace / numSimulations,
|
|
|
|
|
|
probFourth: c.fourthPlace / numSimulations,
|
Add LLWS 20-team double-elimination bracket
The Little League Baseball World Series runs two independent 10-team
double-elimination brackets — United States and International — each
producing a side champion, then a World Championship game and a
Consolation Third Place game between the side runners-up. 38 games in
all. No existing template could express it: every one is single
elimination, at most with a bolted-on third-place game.
Adds the llws_20 template plus dedicated generation and advancement,
following the same bespoke-routing pattern afl_10 and nba_20 use rather
than the generic ceil(matchNumber / 2) advancement.
The core of the change is loser routing. In the winners bracket a loss
is not an elimination — it drops the team into the elimination bracket
at a specific slot, including the deliberate cross-overs the official
bracket uses (Elimination Round 1 pairs L4/L6 and L2/L8; Elimination
Round 3 pairs each semifinal loser with the winner from the opposite
half). In the elimination bracket a loss is final. Matching the official
modified double-elimination format, there is no "if necessary" game: the
winners-bracket champion is eliminated if it loses the side
championship, dropping to the consolation game.
Rounds are shared across both sides, U.S. taking the low match numbers
and International the high ones, so the scoring config stays one entry
per stage. The existing phases/groups display machinery splits them back
apart into United States / International / Championship tabs.
Scoring lands on exactly 8 point-earning teams, which is the field size
when Elimination Round 4 begins: the two finals decide 1st–4th,
Elimination Final losers take 5th–6th, and Elimination Round 4 losers
7th–8th. 3rd and 4th are distinct because the consolation game is real,
and 5–8 splits into two two-team tiers so surviving Elimination Round 4
is worth more than losing it.
Also:
- Adds an optional nonScoringWinnerFloor to BracketRound. The engine
hardcoded a 5th-place floor for winners of non-scoring rounds feeding
a scoring one, which is wrong inside a losers bracket where a win can
guarantee only 7th. Opt-in, so no existing template changes behavior.
- Fixes TabbedBracketLayout's mobile path, which built its match map
unfiltered and so would have merged U.S. and International games into
one column. No-op for NCAA and NBA, whose groups already cover every
match in their phases.
- Rewrites the LLWS Monte Carlo simulator, which still modelled the
retired pool-play format (5 teams per pool, then a 4-team bracket per
side) and no longer described the tournament being scored. It now runs
the real 10-team double elimination and splits the 5–8 probabilities
into the correct tiers instead of one even four-way split. Legacy
"US:A"/"Intl:B" externalIds are still accepted, read as the side
alone, so seasons configured for the old format keep loading.
Tests replay all 38 games through the pure advancement resolver and
assert each one against the feed labels printed on the official bracket.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAxqBVzfmKJe6WQ6VF9guj
2026-08-03 18:06:56 +00:00
|
|
|
|
probFifth: upperTier,
|
|
|
|
|
|
probSixth: upperTier,
|
|
|
|
|
|
probSeventh: lowerTier,
|
|
|
|
|
|
probEighth: lowerTier,
|
2026-04-08 16:52:10 -04:00
|
|
|
|
},
|
|
|
|
|
|
source: "llws_monte_carlo",
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|