I have a program that scans an image and converts gems to specific numbers. Look at the picture below:

So i have a table with numbers. Number 1 is for yellow gem, 2 for blue, etc…
Like:
A B C D E
1 | 1 2 3 4 5
2 | 3 5 2 4 1
3 | 1 4 4 1 2
4 | 3 3 2 1 5
5 | 5 1 5 2 5
I want to calculate a step, to get 3 equal numbers (gems) horizontally or vertically. For example, in this table if i swap E2 with D2, D2 will be 1, and D2,D3,D4 creates a valid step, because it’s all 1. I’m using VB.NET 2010.
My table is 8×8 size, it’s just an example above.
At now i’m just have the values in multiple variables (A1=1, A2=3, so on..)
I hope you understand my question, any help would be appreciated.
Here you go:
And here is the tuple class I used.
BTW: I converted the it from C# to VB.NET from a question on StackOverflow
Running the application give this output:
This program can work with any board size. The program is based on the way I search for matches in the game (which I suppose is brute-force).
Edit
It appears the solver was not able to find matches on the first gem (see sample below).
If the algorithm were applied on the sample above, no matches would be found.
I’ve fixed that now. There is now an
IsMatchOnFirst()method to handle those cases.See the updated code for changes.