Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BraveVN · Nov 09, 2014 at 02:57 AM · algorithmanchorpuzzle

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

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EvilTak · Nov 09, 2014 at 03:43 AM 0
Share

Are your shapes going to be rectangular only? Or other shapes and concave polygons too?

avatar image BraveVN · Nov 09, 2014 at 03:57 AM 0
Share

$$anonymous$$y shapes has circle, lozenge, triangle, halfmoon, etc, not only rectangular. Do you have any ideas ?

avatar image EvilTak · Nov 09, 2014 at 04:28 AM 0
Share

I'm hoping that your halfmoon etc. shapes don't have curves. If they did, it would make things twice as hard.

avatar image EvilTak · Nov 09, 2014 at 04:32 AM 0
Share

But if you plan on having only one solution, it's fairly easy. Just break up the final shape into random smaller shapes (in the editor) and check whether the shapes are in the required position (which we set in the editor).

avatar image BraveVN · Nov 09, 2014 at 05:00 AM 0
Share

thanks for your reply, but I think your solution does not work with me. $$anonymous$$y game plan is 1 shape - many solutions so if I break up the final shape into random pieces, I just having 1 solution for 1 shape. Besides that, don't worry about curved shapes and pieces because I already have a way to do with it.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ricardo_arango · Nov 12, 2014 at 05:49 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by tanoshimi · Nov 09, 2014 at 08:18 AM

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.

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BraveVN · Nov 09, 2014 at 08:31 AM 0
Share

It's a great idea but how OnTriggerStay can check if pieces are inside the Collider fences ? Because I think that user can move a piece in and out the collider many times

avatar image EvilTak · Nov 09, 2014 at 08:33 AM 0
Share

I don't think that OnTriggerStay will work... because it will detect objects on the edge of the collider too, so even if the shapes don't fit, the OnTriggerStay will say that the shape is complete...

avatar image BraveVN · Nov 09, 2014 at 08:39 AM 0
Share

Simple game but complex solution.

avatar image BraveVN · Nov 09, 2014 at 08:41 AM 0
Share

Hi tanoshimi, you can view the image in the order 1,2,3 as the same above
Thanks

[1]: http://i.$$anonymous$$us.com/iUIEI03vb99XA.jpg

[2]: http://i.$$anonymous$$us.com/iFxVm9bv0YVFl.jpg

[3]: http://i.$$anonymous$$us.com/iIqAjyaWxbnWS.jpg

avatar image tanoshimi · Nov 09, 2014 at 08:42 AM 0
Share

Ok, so you know when the level starts whether a fragment is within the "completed puzzle" area, and you can keep track of each OnTriggerEnter/ OnTriggerExit after that to know at any one time which shapes are still outside. The only tricky bit is knowing which shapes are completely inside the puzzle area. You can do this a couple of ways - for your example I'd add multiple edge colliders to each side of the shape and check that they had all fired an OnTriggerEnter event.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Check connection to ground algorithm? 0 Answers

Room Path Generator 1 Answer

how to add a function to Leveling a Character useing the Fibonacci sequence? 2 Answers

How to instantiate and delete spheres based on incomming coordinates stream 2 Answers

How to connect generated points on a sphere? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges