Problem
Design an object-oriented solution to compare two players’ hands in a card game similar to poker.
You are given two hands (each a fixed number of cards; assume 5 unless you state otherwise). Each hand has a hand type (e.g., three-of-a-kind, pair, full house, etc.).
Requirements
-
Compare two hands
and return which one is larger (or if they tie).
-
If the two hands have
different types
, the winner is decided by the
type ranking
(e.g., full house > three-of-a-kind, etc.).
-
If the two hands have the
same type
, break ties by comparing the relevant card ranks in order.
-
Example: for three-of-a-kind,
8883x
should beat
7773x
because 8-trip > 7-trip (assume remaining kickers are compared after the trips if needed).
-
Provide an extension mechanism:
-
Implement
add_type(type_id: string, matches_function: function)
that registers a new hand type and how to detect it.
-
The main
evaluate
function takes an extra parameter
evaluation_orders: array<string>
that specifies the
type precedence
for comparing hands (allowing different games/rulesets).
Deliverables
-
Sketch the class/module design (key classes, interfaces, responsibilities).
-
Explain how
add_type(...)
and
evaluation_orders
work together.
-
Describe the comparison logic, including tie-break rules and how to represent a hand’s “comparison key.”
You may assume card ranks are totally ordered (e.g., 2..A) and suits exist if needed, but keep the design extensible.