macmac

About macmac

macmac is a game that builds intuition for Markov Chain Monte Carlo (MCMC) — one of the most important ideas in computational statistics and machine learning.

In MCMC, the goal is to draw samples from a probability distribution. The challenge is doing it efficiently — capturing the shape of a distribution with as few samples as possible. That's exactly what you're doing in this game.

How it works

Each level shows a target probability density function \(p(x)\). You click to place samples. As you add points, a kernel density estimate \(\hat{q}(x)\) builds up to show what your samples imply about the underlying distribution.

Scoring

Your score is based on two factors: how accurately your samples match the target distribution, and how efficiently you placed them.

Shape match is measured by the mean squared error between the target PDF and your KDE, both normalized to the same peak height. This compares the visual shape directly:

$$\text{MSE} = \frac{1}{n} \sum_{i=1}^{n} \left( \frac{p(x_i)}{\max(p)} - \frac{\hat{q}(x_i)}{\max(\hat{q})} \right)^2$$

where \(p(x)\) is the target density and \(\hat{q}(x)\) is the KDE from your samples. Both are scaled so their peak equals 1, then compared point by point. If the curves look the same, MSE is near zero.

Time bonus rewards speed. A fast solution earns up to 2,000 extra points, dropping continuously to zero over 60 seconds.

The final score:

$$\text{Score} = \underbrace{\operatorname{round}\left( \frac{8000}{1 + 100 \cdot \text{MSE}} \right)}_{\text{shape match}} + \underbrace{\operatorname{round}\left( 2000 \cdot \max\left(0, 1 - \frac{t}{60}\right) \right)}_{\text{time bonus}}$$

The shape match component (up to 8,000) measures how well your curve fits the target. The time bonus (up to 2,000) rewards efficiency — there is no explicit click penalty, but more clicks take more time. The tension: speed versus precision.

Why it matters

MCMC methods are used everywhere — from Bayesian inference to protein folding to language models. The core question is always the same: how can we represent a complex distribution with a finite set of samples? This game lets you experience that question firsthand.

Generated levels

Every time you visit the home page, you see a fresh grid of procedurally generated levels. Each level is created from a seed using a deterministic algorithm — the difficulty rating (1 to 10) directly controls the number of peaks, how closely they overlap, how unequal they are, and how much noise is added. Simple levels (1–2) have a single clean peak; hard levels (7+) have many overlapping modes with noise.

The grid adapts to your skill. As you play more, levels center around your player rating so you always face an appropriate challenge. You get 3 resets per level — after that, you can regenerate a fresh level at the same difficulty.

Weighted scoring

Your raw score (shape match + time bonus) is scaled by the level's difficulty: \(\text{weighted} = \text{raw} \times \frac{d}{3}\) where \(d\) is the difficulty rating. Medium levels (\(d \approx 3\)) get a 1× multiplier; harder levels reward proportionally more.

Your player rating is an exponential moving average of your performance across difficulties — it tracks what difficulty you can handle well. The leaderboard ranks players by their best weighted score and by rating.

Battle mode

Battle mode is real-time 1v1. Both players receive the same generated level and have 20 seconds to match the target distribution. You can see your opponent's KDE building as a shadow curve — but not their click positions.

If either player reaches 98% accuracy before time runs out, they trigger a jackpot and win instantly. Otherwise, the higher score wins. Battle results update your ELO rating (K=32, starting at 1200). Matchmaking pairs players with similar ELO.

Created by Neo Mohsenvand