Jump to content
  • Advertisement
Sign in to follow this  
Proudcastle

How do I recognize patterns (like in TwoDots)?

This topic is 1169 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,

 

I am new here, so I hope that's the right part of the forum.

 

I currently working on a "small" mobile game. Not a clone of TwoDots(!) but I need to recognize patterns like they do. I can think of several ways to do it, but none of them are actually really smart... especially when it comes to non-squares/rectangles.

 

[attachment=26359:Patterns.png]

 

My idea was to store the players touch directions. For the blue square this would mean {1,2,3,4} if you start bottom left and move counterclockwise. Then I could simply check the number of elements in the array (=4). 4 means a possible square and if all numbers are different it is a square. To simplify this I could just check if the start- and end-dots ([3|3] = [3|3]) are the same and if there are 4 elements in the array it is a square.

 

The problems start with the purple square. Starting bottom left and counterclockwise again there would be the following sequence {1,1,1,2,2,2,3,3,3,4,4,4}. If start- and end-dots are the same there might be an rectangle/square. But what do I do now? I can count all numbers (3x1, 3x2, 3x3, 3x4) and see that all numbers appear 3 times. But sadly that doesn't qualify for a square because [1,2,1,2,1,2,3,3,3,4,4,4] would also close the pattern but is not a square. To solve this I could divide the sequence by numbers {[111],[222],[333],[444]} and if all appear equally then I have a square. To check for rectangle I can just count opposite sites. If 1 and 3 appear equally and same goes for 2 and 4 then I have a rectangle or square.

 

Well... the green one really makes my brain hurt because I want to know if the pattern encloses any dots. Green is definitely not a rectangle nor a square. I know that there might be any dots enclosed because there are more than 4 elements stored in the array and the start- and end-dot are the same but how do I get the three question marks? Same goes for the blue dots which are enclosed by the purple square.

 

I am totally lost at the green question marks and I don't think that my approach for the blue and purple square are the best solution. It would be great if someone had an advice for me.

 

Thanks

proudcastle

Edited by Proudcastle

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!