AI think AI can

Poker is a fairly large problem set, but not as large as actually playing poker (or a derivative). Thankfully, Poker Kingdoms does not have be able to watch the player for bluffs and other non-mechanical game devices that exist in the traditional game.

What it does have to do, is scan the board for a playable hands, and rank them. On the surface, this seems like a similar problem to games like Puzzle Quest, scan the board and look for a pattern, and make a play. Puzzle Quest has 3 valid patterns (2, 2x1, 2x2) to search for. Poker Kingdoms has 11, and, by nature of the game, they are each 5 tiles, and, as raised in the early parts, can exist in any set of 5 congruous tiles.

The developers of Puzzle Quest insist that there is no solid AI behind their game, it doesn't plan its choices, and possibly doesn't even rank them if multiples exist. The latter can’t work in Poker Kingdoms, every possible set of 5 cards produces a valid hand, but a High Card hand is not worth very much at all.

For the curious, the 5x5 board which Poker Kingdoms seems to play best on, has just a bit more than 17,000 available moves at any point in time - some cards can be hidden, so we need to find out all possible results, not just all actual results as could be done in Puzzle Quest. That’s

My initial attempt tried to be elegant, for each hand type, it would scan the board, and start a ‘walker’. Walkers collected a set of points, testing each available move from the last point, and spawning a new walker to follow that path.

0>10<10 10 1
2 32 32>32<3

0 10 10>10<1
2>32<32 32 3

0 10 10<10>1
2<32>32 32 3

0,1,3,2 && 0,2,3,1
1,0,2,3 && 1,3,2,0
2,0,1,3 && 2,3,1,0
3,1,0,2 && 3,2,0,1
  • this is a subset of actual generated walks, I’ve ignored diagonal steps.

As these walker progressed, they would check against their respective hands, and stop spawning if they were no longer valid. If they reached 5 valid cards, they’d add a selection to a growing list of valid moves, and eventually return the move that scored the most points.

This worked.

The computer could walk the board and find visible hands.

Aside: part of my encapsulation means flipped cards are invisible to every other element of the game, the representation of face/suit is private, and the getter reads the flipped bool. I would have to go out of my way to let the computer cheat.

Because it couldn't read flipped cards, it could break if there was no sets of 5 congruous cards, and it took no risks (playing a flipped card scores higher).

It was also game-breaking slow. On a high end machine, it was taking over a minute to scan the board in some cases - and even set as a background thread, this would stall the game play for far too long - I wasn't building Civilization here, without the background thread, the game could lock up for long enough for Windows to think it had failed.