some code for dealing with tilegrid puzzles