Snakes and Ladders · a 101-state Markov chain
Exact game length for any die, from the repo’s model.py in your browser
Run the model
Starts Python in this page (Pyodide 0.29.5 with NumPy), imports the repo’s model.py and simulation.py unmodified, and builds the 101×101 transition matrix. Then change the die from d1 to d24, scrub through turns, sample games from the chain, roll real dice with simulation.py, and run the repo’s tests.
About 8.1 MB from cdn.jsdelivr.net, cached after the first run. The optional test run adds about 1.6 MB.
One game is model.simulate_game(T) after np.random.seed(seed).
simulation.py: roll real dice
Plays games with roll_die() instead of the matrix and tallies every move into an empirical transition matrix, as simulation.main() does with seed 42. It always rolls a d6.
The repo’s tests
test_model.py under pytest 8.3.5, unmodified. Several tests play tens of thousands of games, so this takes a while in the browser.