Finding the best poker hand in a connected grid structure where order matters
I recommend you use breadth-first search (BFS) through the state space.

Start by trying to find (partial) straights that are ascending.  For each possible starting position (there are 12 possibilities), use BFS to search for a path that starts at that position and makes an ascending straight (i.e., the numbers increment by one each time you move forward).  This will find you the longest ascending straight.

Next search for descending (partial) straights in the same way.  This will find you the longest descending straight.

You can also search for straight flushes in this way, too.

Next for x-of-a-kinds in the same way.  This will find you the longest sequence that are all of the same rank (e.g., two-of-a-kind, three-of-a-kind, four-of-a-kind, five-of-a-kind).

Next search for flushes in the same way.  This will find you the longest sequence that are all of the same suit.

You can look for two-pair and full-house separately, with a different method tailored to that problem.  Enumerate all pairs (i.e., all pairs of adjacent positions where the two cards have the same rank).  Now check whether any two of those pairs are adjacent; if so, you have found a two-pair.  Similarly, enumerate all three-of-a-kinds (i.e., paths of length 3 where the three cards have the same rank).  Now check whether any pair is adjacent to any three-of-a-kind; if so, you have found a full-house.

In this way you can find the best poker hand in the grid.  I expect that this will be very efficient.