Problem 334. Poker Series 03: isFullHouse
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.
--------
A full house is three cards of one rank (column) and two cards of a different rank. The Ace (first column) is the highest rank. The columns represent A, 2, 3, ... K. When there is a choice between two possible three of a kind, choose the higher. Once a three of a kind is choosen, choose the highest possible pair.
This hand matrix:
0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0
represents a full house, so the return value from the function is TRUE.
This hand matrix does not:
0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
so the return value should be FALSE.
This hand matrix does represent a full house
1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
Remember, hand matrices can contain any number of 1's from 0 to 52.
0 1 1 0 1 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 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
Would be FALSE for this function.
A second output argument should come from this function. It is a usedCards Matrix. It is of the same form as the hand Matrix, but it only shows the cards used to make the full house. If more than one full house can be made, return the higher ranking one (the one with the highest ranking three of a kind. Ace being the highest. Ties are broken with the highest ranking pair). If different suits are possible for the same full house, return the ones higher up in the matrix.
Solution Stats
Problem Comments
-
1 Comment
This problem needs more test cases with the three of a kind appearing before the pair, such as:
1 0 1 0 0 0 0 0 0 0 1 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0
Solution Comments
Show commentsProblem Recent Solvers68
Suggested Problems
-
Remove the small words from a list of words.
1489 Solvers
-
Omit columns averages from a matrix
581 Solvers
-
346 Solvers
-
60 Solvers
-
420 Solvers
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!