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 bf0wl3 · Apr 13, 2012 at 01:03 PM · 2dgridmatrixalgorithmshapes

Grid Shape Detection

Hello,

I am working on a project that has a 2D-like grid system that have cubes grouping dynamically with one another to create a new shape. When the shape becomes a solid "block" shape, it is then "complete".

What would be the best algorithmic approach to detecting that all the shapes grouped with one another are a "completed block"?

Background:

  • I have a dynamic amount of cubes that fit into a single grid spot on the playfield grid.

  • All connected/touching cubes are grouped together in a "cube group".

  • I need to check this cube group's current "shape" by iterating through all the cubes inside of it; if it's entirely filled in, then it should be set as "complete".

Incomplete Shape

 1 1 1 1 1
 1 0 0 0 1
 1 0 0 0 1


Complete Shape

 1 1 1
 1 1 1
 1 1 1


Thanks in advance for any insight into this! Cheers~

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by bf0wl3 · Apr 18, 2012 at 07:09 PM

Thanks for the input and suggestions.

The solution I came up with was really quite simple in theory. I'm not sure if it's the "best" or most optimal way, but I am only performing the check every-so-often and not on a per-frame basis.

I got the minX-maxX and minY-maxY ranges of the child objects inside the grid shape. I took the (maxX-minX)*(maxY-minY) and compared that to the childCount of the grid shape.

Since I am only looking for a completed shape, if the grid shape is a 4x4 shape it will check that the childCount is 16. Otherwise it is not "completed" yet.

I had also done an exhaustive loop checking the top-left to the bottom-right of the grid object and making sure there is an object in that grid space, which worked, but is not quite as good as the childCount.

Thanks again, the Unity community rocks!

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 inewland · Apr 13, 2012 at 06:49 PM

Just a stab in the dark here, from what I understand...

Couldn't you just iterate each row looking for '1'...if each row has a 1 bool success, otherwise return false?

You could have predefined arrays setup defining your shapes.

Cube Shape


    Array[2][2] = { 1, 1,
                    1, 1 }; 

When iterating the shape, look for matches in your arrays.

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 rutter · Apr 13, 2012 at 06:58 PM

You might try some variation on flood fill algorithms, or check out this Stack Overflow thread which seems to be asking a very similar question.

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

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

6 People are following this question.

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

Related Questions

How to de-pixelize pixel art (smooth out) 2d 0 Answers

2D Sandbox physics problem 1 Answer

board game algorithm 0 Answers

How to make 2d distortion? 2 Answers

Get position from Isometric TileMap 1 Answer


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