Monday, December 17, 2007

Javascript, Settlers of Cataan and Randomness

My roomates and I tend to play a lot of Settlers. One common complaint is that the dice rolled unfairly. Even though all 3 of us are trained computer nerds and realize that dice cannot be completely fair over a very short cycle (average game is 70 rolls), we still like to complain about how we lost because the dice rolled unfairly or at least in inopportune ways.

In order to track what the rolls were, I wrote a dice roller. Its very simple javascript code and users javascript's built in random function to roll "dice". The nice thing is that it keeps track of dice rolls and can plot the aggregate distribution of rolls as well as rolls over time. Check it out here (or even better, use it in your next settlers game!!)

http://keeda.stanford.edu/~radoshi/dice/


This was my first javascript program ever and I have to admit that I was pretty impressed with how easy it was to write something like this in a language that I had never touched. I was even more impressed with MochiKit and PlotKit - the two libraries that allow me to generate the spiffy charts. Another advantage of writing client side javascript: Visit the page once and you have the "application" in your cache - no more server communication required for endless hours of settlers play.

No comments: