evan_tech

Previous Entry Share Next Entry
02:57 am, 29 Apr 06

diplomacy xul

I went out to dinner with Darin Fisher (and others) last night, following a talk he gave on Firefox. This finally prompted me to get around to starting work on my Diplomacy viewer.

If you don't know it, Diplomacy is a great game that's decades old. (That site is full of good resources, including the rules...) It's like Risk but with most of the chance removed -- I resolved never to play Risk again when I attacked someone with 80 armies and still lost to their ~30 -- and bit more abstract strategy with a whole lot of schmoozing added. And it plays by mail in a very relaxed sort of way, which is nice for me 'cause I don't have a lot of free time to dedicate to today's games. (I'm sure WoW is fun, but I think I'd be too depressed to enjoy it realizing I was dedicating all these hours to incrementing numbers.)

Anyway, Diplomacy the game is fun, but the site we play it with is sorta lacking. It definitely gets the job done, but it has a bunch of misfeatures, like pretty much everything being done by form POSTs (so you can't bookmark any URLs), being generally slow, and producing nearly unreadable maps (you can see my current game here), which are made even worse by my dpi problem.

So I had been thinking about making a DHTML Diplomacy viewer/planner that would let you shuffle the pieces around. But the tricky part is that showing the moves in a turn involve drawing arrows on a map, which are hard to do with HTML*. I had thought this would be a fun opportunity to check out the Firefox canvas implementation. (I eventually switched to the SVG+DOM approach.)

Partway through implementing this, and looking up something on quirksmode for the n millionth time, I realized that I'm Firefox-specific already (using SVG, and I don't test on IE anyway), and, thinking of talking with Darin, I may as well use the more pleasant API and widgets of XUL. It's actually pretty straightforward. Of course, except, when you want to do something slightly outside of the box (which apparently includes "putting something in a scrollable region but still being able to compute mouse coordinates on the underlying surface") involved some kinda-gross hacking, but I figured it out after a few hours.

Anyway, I've got general board layout, some status file parsing, and some UI wrapped around it working. You can run it directly out of the repository, too, though of course it only works if you're using Firefox: dip.xul. But it's still mostly vaporware.

* With maybe 30 vertices on the board graph, 6 edges per vertex, and probably averaging around 3 moves per vertex+edge, I suppose I might be able to pregenerate all the possible move graphics offline...