Drawing puzzles with the Haskell Diagrams framework

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: |
solution: |

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.png and 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!

4 thoughts on “Drawing puzzles with the Haskell Diagrams framework

  1. Silke

    This is really great!!! Thank you very much! In Word I need hours to create a Compass puzzle, and of course it doesn’t nearly look like that. – What about Tapa puzzles…? ;-)

  2. rob Post author

    I’ve uploaded (several…) new versions of the command-line tool to hackage, with two significant changes. 1. it builds without cairo by default, which also means that png output won’t be available. 2. it should be possible to build with cairo on windows at all (thanks James!). If you want the cairo version, you’ll need to run “cabal install puzzle-draw-cmdline -f cairo”.

    Also, since at least two people have asked: I can’t see what puzzles are rendered with the web app, and I won’t change that. But you’ll have to trust me on that, it would be easy to change.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s