900,000 Chutes & Ladders per hour

Every Thursday at work, during our lunch hour, several of us get together to play board games. We play a different game each week, and aside from a few tries at new games, we tend to rotate through the same three or four games each week. In an attempt to add a little variety, we discussed some alternative new games a few days ago.

Someone mentioned she could bring in Candyland, and of course because of the skill level involved in playing (zero, actually), this was vetoed with a chuckle. Talk went to other similar games, such as Chutes and Ladders, in which the player is just along for the ride. You roll the dice, you move, you have no decision-making power. The game is entirely deterministic except for the dice rolls.

The game is entirely deterministic except for the dice rolls… it could be played by robots. Or computers. Instead of actually playing the game, a perfect computer simulation could be made to play the game for us. The computer can play a lot faster than we could. In fact, it could probably play the game a few million times over lunch in a simulation.

This weekend, I made just such a simulation. I did not do Candyland, as I do not remember the rules terribly well, but I did Chutes and Ladders. Between my memory and Wikipedia, I believe I captured all of the rules. It only took about 20-30 minutes and is implemented entirely in JavaScript. This is partly for its ubiquity and partly because I was thinking I could later add in a graphic element (for instance, using Scriptaculous) showing the moves. (It currently keeps a model of the board in memory, but displays moves as a rolling text list of items such as “Brian rolled a 5 and moves to square 20.”) A friend today even mentioned it would be interesting to generate a heat-map of the squares to see which ones are traversed the most and least.


My Chutes and Ladders Simulater can be found at https://netninja.com/fun/cnl/, with the interesting code itself in cnl.js. On my machine (Firefox, on a 1.6GHz dual core Mac), it can play 1,000 games in about 4 seconds. This calculates out to 900,000 games in an hour. Obviously, I could get more speed out of it with an implementation in C, but I figured it wouldn’t be as fun and interactive to the internet as a whole than an interactive web page.

Posted in: Code Dear Diary Games Work

4 thoughts on “900,000 Chutes & Ladders per hour”

    1. At the other end of the spectrum, the iPhone 3G (not 3GS, which has a faster processor) can only get through about 300 in 10 seconds. It has a throttle that kills execution after 10 seconds of not returning from the button-press event.

Leave a Reply

Your email address will not be published. Required fields are marked *