I have generated a matrix array of booleans (I generate it as widget) that I can click to make a pattern.
After the pattern is made I use FloodFill to validate that it’s correct.
- No separated squares.
- All squares need to be connected to each other (has to be 1 continues pattern)
After the pattern is validated I want to write another function that breaks it apart into smaller pieces each of them being 5 squares long, I do that by:
- Finding first true value in my square array.
- I get it’s row & col & index in matrix.
- check that it’s within my matrix bounds, is Clicked, is NOT Visited.
With that I got some separated squares that got trapped by that logic. So I think about trying
- To check each direction one by one and it’s neighboring square to see if that piece has options to expand. (Only going 1 square away from current index).
- Prioritze square with lowest options.
- if current piece has no option to expand then backtrack to previous piece index and go from there ?
That’s what I got so far. Is there maybe a better way to approach this ?