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
1
Question by Persona · Sep 21, 2010 at 07:36 PM · collisiondetectionpuzzlematching

Pattern Detection

If I was making a tetris style game but when certain colored balls touched each other in a specific pattern, how would I check to see if that pattern was reached?

Example: Four balls make an "L" shape. How do you check if that certain pattern was formed?

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

1 Reply

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

Answer by Jesse Anders · Sep 22, 2010 at 04:35 AM

To keep things simple, we'll use your 'L' shape as an example. (I'm assuming that we're talking about an 'L' shape in its 'default' configuration; if the shape can be mirrored and/or oriented differently, a little more work will be required, but the concepts are the same.)

I'm assuming that the game board is (or could be) represented as a 2-d array; I'll also assume that row numbers increase upwards. For any given cell (i, j), you can determine if there's a corresponding L shape by checking the colors of cells (i, j-1), (i, j-2), and (i+1, j-2). The query needn't be performed for cells in the last column and in the first two rows, since the query would go outside the array bounds. If the colors of the three checked cells are the same as the query cell, you've found an 'L' pattern.

Similarly, you can check to see if any specific ball is part of an 'L' pattern by performing four checks similar to the one described above, one for each of the four positions the ball can have relative to the L.

The ideas described above can be generalized to handle different shapes, and different configurations of those shapes. When and how the tests should be performed depends on the game mechanics. Depending on the circumstances, you might be able to get away with performing a brute-force search for all patterns every time the board changes. Or, you could perform searches 'on demand' as needed. (Again, the details depend on the context.)

Comment
Add comment · Show 3 · 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 Persona · Sep 22, 2010 at 05:03 PM 0
Share

Is there anyway to run it against a template of the shapes? Like to compare it with the shape?

avatar image Jesse Anders · Sep 23, 2010 at 05:02 AM 0
Share

Sure, you would just generalize the approach I described for the 'L'; it would most likely involve creating a 'shape definition' class, storing an array of shape definitions, and then perfor$$anonymous$$g the test described above for each shape. (I can't really fit a detailed description into a comment, but feel free to ask any specific questions you might have. Alternatively, you could post a thread to the forums on the specific topic of how to make the pattern detection generic.)

avatar image Persona · Sep 23, 2010 at 03:52 PM 0
Share

Alright, thanks

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

No one has followed this question yet.

Related Questions

chronological order of collision to give a winner unity 2d 4.3 1 Answer

Collision Enter one of the objects ? 1 Answer

Collision detection how? 1 Answer

Transferring values from one script to another script? 2 Answers

Weapon System with collide detection (Helps with script pls)!!! 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