Yesterday I was just playing Jigsaw Puzzle and somehow wondered what would be algorithm for solving it.
As human, steps which I followed where:
I was wondering what would be the efficient algorithm to solve this puzzle efficiently and what datastructure would provide optimum efficient solution.
Thanks.
A popular strategy is to put the edges of the puzzle together first because, with one straight edge, the pieces are easier to identify and put together. “There isn't a single strategy that will work for 100 percent of puzzles, but in the majority of cases, it is easiest to start with the edge,” McLeod says.
Puzzles of 1000 pieces also usually involve a smaller cut pattern that is repeated 4 or 6 times over the whole jigsaw, and that smaller cut pattern usually also has 180 degrees of rotational symmetry, so a particular shape may appear 8 or 12 times in the puzzle (although with truncation for edge pieces).
Jigsaw puzzles exercise the left and right sides of your brain at once. Your left brain is logical and works in a linear fashion, while your right brain is creative and intuitive. When you're doing a jigsaw puzzle, both sides are engaged, according to Sanesco Health, an industry leader in neurotransmitter testing.
Solving problems like this can be deceptively complicated, especially if no constraints are placed on the size and complexity of the puzzle.
Here's my thoughts on an approach to writing a program to solve such a puzzle.
There are four key pieces of information that you can use individually and together as clues to solving a jigsaw puzzle:
So what kind of information will the program will be supplied - let's assume that each puzzle piece is an small rectangular image with transparency information used to identify the portion of the puzzle piece that represent non-rectangular edges.
From this, it is relatively easy to identify the four corner pieces (in a typical jigsaw). These would have exactly two edges that have flat contours (see contour map below).
Next, I would build information about the shape of each of the four edges of a puzzle piece. This information can be used to build an adjacency matrix indicating which pieces fit together.
Now we can prune this adjacency matrix to identify just those pieces that have smooth color transitions in their adjacent configuration. This is somewhat tricky because it requires a level of fuzzy matching - since not every pixel-to-pixel boundary will necessarily have a smooth color transition.
Using the four corner pieces originally identified, we should now be able to reconstruct the dimensions and positions of all of the pieces in the puzzle.
A convenient data structure for representing edge shapes may be a contour map - essentially a set of integers representing the incremental deltas in distance from the opposing side of the image to the last non-transparent pixel in each of the four sides of the puzzle piece. Pieces that match should have mirror-image contour maps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With