Problem 386. Poker Series 10: bestHand

The Poker Series consists of many short, well defined functions that when combined will lead to complex behavior. Our goal is to create a function that will take two hand matrices (defined below) and return the winning hand.

A hand matrix is 4x13 binary matrix showing the cards that are available for a poker player to use. This program will be expandable to use 5 card hands through 52 card hands! Suits of the cards are all equally ranked, so they only matter for determination of flushes (and straight flushes).

For each challenge, you should feel free to reuse your solutions from prior challenges in the series. To break this problem into smaller pieces, I am likely making architectural choices that are sub-optimal for speed. This is being done as an exercise in coding. The larger goal of this project can likely be done in a much faster, but more obscure way.

--------

Find the best hand using the definitions from earlier in this series.

out.code is:

  1. Straight Flush
  2. Quads
  3. Full House
  4. Flush
  5. Straight
  6. Three of a kind
  7. Two pair
  8. Pair
  9. High Card
  10. No valid Hand

out.cardsUsed is the same as is returned from the functions defined earlier for each type of hand.

This hand matrix:

0 1 0 0 1 0 0 0 0 0 0 0 0 
0 0 1 0 0 0 0 0 0 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 0 0 
0 1 0 0 0 1 0 0 0 0 0 0 0

represents a three of a kind, so the return code is 6.

Solution Stats

31.16% Correct | 68.84% Incorrect
Last Solution submitted on Jul 06, 2022

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers42

Suggested Problems

More from this Author51

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!