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.).
8883x
should beat
7773x
because 8-trip > 7-trip (assume remaining kickers are compared after the trips if needed).
add_type(type_id: string, matches_function: function)
that registers a new hand type and how to detect it.
evaluate
function takes an extra parameter
evaluation_orders: array<string>
that specifies the
type precedence
for comparing hands (allowing different games/rulesets).
add_type(...)
and
evaluation_orders
work together.
You may assume card ranks are totally ordered (e.g., 2..A) and suits exist if needed, but keep the design extensible.
Login required