Problem 391. Poker Series 11: selectBestHand
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.
--------
Select the best hand using the definitions from earlier in this series.
out.hm{1} = cards used from the first hand matrix; out.hm{2} = cards used from the second hand matrix; out.winner = 1,2 or zero for a tie;
Standard poker ranks apply: Straight flush is best, high card is worst, with many gradations within each rank.
Solution Stats
Problem Comments
-
15 Comments
Many of the issues could have been easily solved with a better design choice (for instance, cases 5 and 9 are only an issue because the functions that identify both hands do not store the highest cards values). Storing the array usedCards is not useful, it would be best to store a number representing the hand, and the values of the highest cards or a number representing them.
For those asking why 2-3-4-5-6 beats A-2-3-4-5: in poker, the rank of a straight is determined by the card at the high end. So 2-3-4-5-6 beats A-2-3-4-5 because 6 beats 5. The ace becomes a low card.
smartest non-cheating solution is scored 480? omegaLOL
Solution Comments
Show commentsGroup

Card Games
- 18 Problems
- 25 Finishers
- Card Game
- SET (the card game)
- Poker Series 01: isStraightFlush
- Mongean Shuffle : 2
- Mongean Shuffle
- Combine Cards to make 21
- Poker Card Deal!
- Clock Solitaire
- SET (the card game)
- Poker Series 11: selectBestHand
- Poker Series 10: bestHand
- Poker Series 09: IsHighCard
- Poker Series 08: IsPair
- Poker Series 07: IsTwoPair
- Poker Series 06: isThreeKind
- Poker Series 05: isStraight
- Poker Series 04: isFlush
- Poker Series 03: isFullHouse
- Poker Series 02: isQuads
- Poker Series 01: isStraightFlush
Problem Recent Solvers35
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!