Need an Algorithm to solve the Geometric Puzzle

Hi there, I’m trying to make a geometric puzzle game for kids. I have done all the dragging stuffs. I’m confused on the checking part of the game. After the user has put all the pieces together, how can I check if the user is correct, it means there are many ways to complete 1 shape, like this:

alt text

I thought about using anchor point to handle this but this idea same to lame and just working at the unique cases. Here is an image with anchor point (the black asterisk):

alt text

And here is when I move the red square to the right, it meets the anchor point but not fit the gray shape.

alt text

How can I handle this problem ? Are there any algorithms for it ?
Thanks

I would do two things:

  1. Add snapping, so the pieces are placed in precise locations. You could use a grid of 5pixelx5pixels, or so, whatever fits your design.

  2. Render the pieces with a replacement shader to a RenderTexture (it could be half the size or smaller : 256x256, etc), with the result being a black & white image : white for pieces, black for everything else. I would then compare the result with a “template” or “correct” image.

There are many algorithms that can do image comparison. The simplest one and which should suffice for this would be to do a pixel-by-pixel comparison. So you would take pixel [0] from the RenderTexture and subtract pixel [0] from the Template texture. If the different is zero, then they are equal.

You can add a threshold to compensate for any errors. For example, if 98% of pixels are the same, then the images are about the same, and you can then say that the pieces are covering the area correctly.

For some reason I can’t see any image but, from your description, can’t you simply create a box collider that encompasses the extent of the desired completed shape? When all the fragments lie within the collider (which you can easily check with OnTriggerStay), the puzzle is complete.