I am trying to find the best poker hand in a connected grid, where order matters. An illustration is the best way of explaining the situation.
This grid has 12 random cards, in random positions. Each card is connected to the vertically, horizontally and diagonally adjacent cards.
The hands are standard poker hands but no extra cards are allowed – only the cards which constitute the hand. So, a pair is only two cards connected, four of a kind is just four cards connected, etc.
Order matters, so a straight must be in the correct order (e.g. 10, J, Q, K, A is valid but 10, A, J, Q K is not). There is no straight in this particular grid, the 10s are not connected to the Jack directly.
I am looking for an algorithm that finds the best hand for a random grid. The grid isn’t ever going to be much larger than this grid of 12.
I am also looking for an algorithm that finds out if there are no moves at all – this would alert the player to this fact to save them searching for too long…