Longest Chain AI

Working on a little project and I’m more or less complete with the exception of the AI.

I have a 2D grid that can be populated with 4 different tiles. I basically need the AI to find the largest pattern of like tiles moving in 4 directions only. There is no starting point or ending goal, just find the longest chain without backtracking.

Seems all the AI’s deal with the shortest path only. Is there anything already created that is similar to what I’m looking for?

Start iterating in x and y from each grid node and increment the values if they match. Store the largest incremented number and the tiles that generated that number in an associated array. As you keep iterating and by the time you have completed iterating through the grid the largest number and associated tiles is your array and answer.