CPSC-312-2021/Poker Hand Evaluation

From UBC Wiki

What is the problem?

Poker is a game that is enjoyed by many but played seriously by few. Often, novice players fail to recognize their strongest hand and misjudge the potential of their position. It is not unusual to see a beginner forget about full houses and play exclusively towards straights and flushes. We have created a poker hand evaluation tool that alleviates both of these concerns. At any stage or round of the game, the player can input the available cards into the tool which will then determine the strongest possible hand. They can also then subsequently ask the tool what the next community card has to be in order for them to complete a specific hand. The tool is able to answer these questions very quickly in a legible manner.

What is the something extra?

  • We had originally planned to only evaluate the strongest hand given a set of cards, but we are now also able to find the missing card(s) required to complete a certain hand. This allows players to plan their bets accordingly for the next round.
  • We have also made an optional miniature UI interaction to check what hand you can get from the combination. It is miniature because: a) it can only check when there are five cards b) if they have a straight flush, royal flush b) two of a kind, three of a kind, four of a kind and five of a kind, given you have 2 cards of the same suit in hand.

What did we learn from doing this?

The logical programming nature of the language made some parts very easy. In particular, it was fantastic to be able to "flip" relations around. When we were at first whether the output was true given the inputs, we were able to instantly switch to asking for the input values that made the output true. It was also easy to do plenty of pattern matching such as atoms and strings which made evaluating the poker cards simple.

On the other hand, prolog is a very difficult language to debug as it only allows you to trace the calls. We also struggled with changing a list of words into a list of atoms, which was something prolog was not able to achieve. The other challenge we had was trying to limit the number of inputs for the UI interaction to only take in five inputs as user_string/5 can take an unlimited number of entries. The lack of existing material made it particularly hard to get started.

Link to code