Question

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.

3x4 connected grid of playing cards

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.

The best hand for this grid highlighted: The best hand in this case, a two pair: 10s and Aces

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.

An invalid straight, the cards must be connected in the correct order

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…

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with cs.stackexchange
scroll top