A while ago I alluded to some puzzle rendering project I was working on, today I want to give a small update. It’s a Haskell library called puzzle-draw, the source code is available on github. It’s in a state where it’s useful to me (I used it for the entire marathon set, for instance), not necessarily quite ready for public consumption.
If you just want to play around with it, I’ve hacked together a web demo, below I’ll give an overview and explain how to install the command line tool.
EDIT: The command line tool has since changed to not require cairo by default, see the comments.
I had a couple of goals with this project. For one, I wanted to get my puzzle rendering more automated. I wanted an easier way to draw area-based puzzles than what I was doing with TikZ before, where I was basically drawing the borders by hand. And I wanted to get to know Diagrams and practice my Haskell.
With respect to the programming side of things, I’d like this to eventually provide an easy way to draw new puzzle types even without particular Haskell knowledge (a puzzle drawing DSL as the Haskellers would call it), but it’s definitely not there yet. For the moment, it’s basically a command line tool that knows how to render a hard-coded list of puzzle types from a text description to a variety of output formats.
If you want to play along, either use the web app linked above, or install the Haskell Platform and run
$ cabal install puzzle-draw-cmdline
Now, say you want to create a small LITS puzzle. Create a text file
lits.pzl with the following contents:
type: lits puzzle: | aaaaaa abbbba cbcbbd cccddd eeeeed eeeedd solution: | ...XXX ..XX.X X..XXX XXX..X ..XXXX ...X.X
This is in YAML format. The pipe symbol (‘|’) starts a block of pre-formatted text (minus the indentation). I’ve chosen a more-or-less ad hoc format for every puzzle type for now. For LITS, you specify the puzzle by marking all cells within a room with the same letter. The solution is marked by placing Xs in shaded cells. Check the web app or my example repository for the other formats.
With this, you can call the
drawpuzzle executable installed earlier
$ drawpuzzle lits.pzl
which will by default create two files
lits-sol.png. It’s also possible to render both side by side as for example puzzles, or to render to SVG or PDF:
$ drawpuzzle --format png --example lits.pzl
For now, I’ll probably keep adding puzzle types as I need them and hopefully arrive at a more generic solution at some point. If you’d like to use this and need some changes, let me know. And contributions are of course welcome!