This folder contains the simulation script and Marimo notebooks for analyzing court assignment algorithms.
Dependencies are declared in analysis/pyproject.toml.
cd analysis
uv venv
./.venv/bin/uv pip install .The simulation compares all four court assignment algorithms (Random Baseline, Monte Carlo, Simulated Annealing, and Conflict Graph) and generates comprehensive metrics.
Create or edit analysis/data/config.json:
{
"runs": 100,
"rounds": 10,
"playerCounts": [20],
"numCourts": 4
}- runs: Number of simulation sessions per algorithm
- rounds: Number of rounds per session
- playerCounts: Array of player counts to test (e.g.,
[17, 18, 19, 20]) - numCourts: Number of available courts
cd analysis
npx tsx ./simulation/index.tsThe simulation generates data in analysis/data/:
random_baseline/,mc_algo/,sa_algo/,cg_algo/: Per-engine resultssummary.csv: Repeat pair statistics per simulationpair_events.csv: Individual repeat pair occurrencesmatch_events.csv: Match outcomes with team strengthsbench_stats.csv: Bench fairness metricsmatch_pair_summary.csv: Player pair interaction countsplayer_stats.csv: Win/loss records per playerconfig.json: Configuration and aggregate statistics
comparison_summary.csv: Side-by-side engine comparison
- Repeat pairs: How often the same team plays together across rounds
- Balance: Team strength matching (based on simulated skill levels)
- Bench fairness: Distribution of bench time and gaps between benches
- Win distribution: Player win rates relative to skill levels
Instead of calling the engines directly, this harness drives the actual app in a
browser with Playwright, reusing the e2e/support/pages page objects. It seeds
players + levels into localStorage, generates rounds, records winners (the score
modal in Smart mode), and regenerates — then reads the saved state back for metrics.
It sweeps a concurrency range to load-test the UI and samples CPU/RAM while runs
execute.
The ui block in analysis/data/config.json:
"ui": {
"engines": ["sa", "sl"],
"concurrency": [1, 2, 4, 8],
"durationSec": 45,
"runs": 4,
"rounds": 10,
"playerCount": 16,
"sampleIntervalMs": 250,
"headless": true
}- engines: which shipped engines to exercise —
sa(default) and/orsl(Smart) - concurrency: browser sessions to run at once, one value per sweep point
- durationSec: when set, each cell runs for this many seconds (equal-time load), looping sessions until the window closes — this overrides
runs. Omit it to run a fixedrunscount instead - runs: sessions per (engine, concurrency) cell, used only when
durationSecis unset - rounds: rounds generated per session
- playerCount: players seeded (levels come from
playerProfiles); courts fromnumCourts - sampleIntervalMs: CPU/RAM sampling period
- headless: run the browser headless
cd analysis
npx tsx ./ui_simulation/index.tsThe harness reuses a dev server already on http://localhost:5173, or starts
npm run dev itself (override with E2E_BASE_URL). Output CSVs land in
analysis/data/ui/: sessions.csv, generate_events.csv, resources.csv,
concurrency_summary.csv, match_events.csv, player_stats.csv, config.json.
View them with the ui_load_analysis notebook below.
To compare the UI fairly against the raw engine, generate a baseline that runs the same engines with the same defaults, players, courts and rounds as the UI (and the same teammate-repeat metric), directly in Node with no browser:
cd analysis
npx tsx ./ui_simulation/engine_baseline.tsThis writes analysis/data/ui/engine_baseline.json, which the notebook uses as the
reference. Do not compare against the sa_algo/sl_algo batch — that runs 15–18
players with benching, which makes repeats trivially avoidable and is not comparable
to the UI's tighter 16-players / 4-courts setup.
cd analysis
./.venv/bin/marimo edit ./engine_analysis.pycd analysis
./.venv/bin/marimo run ./engine_analysis.py --host 127.0.0.1 --port 2786Serves all notebooks with automatic refresh on file changes:
cd analysis
uv run serve.pyThen open:
- http://localhost:8765/algorithm_docs
- http://localhost:8765/engine_analysis
- http://localhost:8765/level_tracker_analysis
- http://localhost:8765/ui_load_analysis
Export all notebooks without code cells (output only):
cd analysis
uv run export-htmlGenerated analysis HTML is not checked in. Analysis notebooks, source data, and generated artifacts are available in this repository's analysis/ directory and on GitHub.