Hi,

I’m creating a jigsaw solver, I’ve got the piece identification all done, including calculating a match likeliness for each side of the pieces to other sides of other pieces. The data structure for a piece is as follows:

```
Piece
-> Side (north)
-> Match[] (Matching Side and match likeliness)
-> Side (east)
-> Match[]
-> Side (south)
-> Match[]
-> Side (west)
-> Match[]
```

Where Match could be a class as follows:

```
class Match
{
Side matchingSide;
double matchLikeliness;
}
```

Using the pieces of the jigsaw, and the matches, we can apply the Travelling Salesman Problem to calculate a “best fit” for all the pieces at once based on the precalculated match likeliness values.

My problem is implementation of an algorithm to create this behaviour. The final goal is to create a tree that represents all possible (pruned) combinations for solving the jigsaw.

To simplify the process, I’m trying to only consider the edge pieces to start with so that we can consider it to be just one long line in terms of the tree structure.

I suppose my issue is that the implementation I would need relies on having two sides to each piece, so it’s not just as simple as having a “Node” with a “distance”, since I need more information than that. I need something more like this:

Where each node is a Piece with two separate (known) sides, and a “distance” between each. The goal is to create a path for every combination of the pieces (with pruning for performance). But I’m really struggling to implement this in code.

More info:

Piece:

```
class Piece
{
// Unordered, Side holds directional info
List<Side> sides;
}
```

Side:

```
class Side
{
// The direction this side is facing
Direction dir;
// where Side is the connecting side and the double is the match likeliness
Dictionary<Side, double> matches;
}
```

How would you go about implementing this? Feel free to change the structure of the Piece and Side classes if it proves favourable. I’d greatly appreciate any help with this.

Cheers!