Combinatorics
Card Games
Hand Evaluation
Wildcards
Duplicates

Combinatorics of cardgame hand evaluation for runs, with wildcards and duplicates

Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms

In the fascinating world of card games, hand evaluation is a pivotal aspect, especially when considering runs. A run is a sequence of consecutive cards, typically of the same suit, and is of fundamental importance in games like Rummy. Adding complexity to the evaluation are wildcards and duplicate cards. The combinatorics involved in such systems can be intricate, yet they offer a compelling exploration into the realm of probability and discrete mathematics. In this article, we shall undertake a detailed examination of combinatorics in evaluating card game hands involving runs, focusing on scenarios with wildcards and duplicate cards.

Understanding Runs in Card Games

A run, in its simplest form, consists of consecutive cards that follow one another in a sequence. For example, in a standard deck, `5-6-7` is a run. When evaluating runs:

• Conventional Runs: These adhere strictly to consecutive order without any substitutes. • Wildcards: These cards can be substituted as any card. For instance, considering a wildcard `W`, `5-W-7` can represent the run `5-6-7`. • Duplicates: These are multiple copies of the same card, which can influence the formation of multiple potential runs or emphasize a single run's probability.

Combinatorial Evaluation: Basic Principles

Notation

  1. S: Denotes the number of suits.
  2. R: Denotes the number of ranks.
  3. W: The number of wildcards available.
  4. D: The number of duplicate cards allowed per rank per suit.
  5. n: The length of the run required.

A standard deck, without any wildcards or duplicates, comprises 52 cards (4 suits, 13 ranks per suit).

Basic Combinatorics

For ordinary runs without wildcards or duplicates: • The number of possible 3-card runs in a single suit is calculated through combinations of the ranks. For instance, without duplicates, using (R−n+11)\binom{R-n+1}{1} gives the starting rank position, allowing us to count runs like `A-2-3` through `Q-K-A`.

Wildcards in Runs

Wildcards add complexity by providing flexibility in forming runs. Consider a sequence `5-W-7`:

  1. The wildcard can be `6`, thus completing a valid run.
  2. In terms of combinatorial possibilities, each wildcard addition exponentially increases the number of potential valid sequences.

For analysis, the number of possible runs using `W` wildcards can be calculated as: \\sum\_{k=0}^{W} \binom{n}{k} \cdot \binom{R-k}{n-k}\

Where (nk)\binom{n}{k} selects positions in the sequence that the wildcards will occupy.

Duplicates in Runs

Duplicate cards also play a significant role in combinatorial evaluation. Duplicates allow multiple cards of the same rank, such as in Poker scenarios where a pair contributes to a full house.

• Considering duplicates, evaluate the number of potential sequences: • Calculate using (Rn)⋅Dn\binom{R}{n} \cdot D^n, which accounts for each possible sequence of ranks multiplied by the `D` duplicates for each rank.

Combining Wildcards and Duplicates

Combining wildcards and duplicates involves a synthesis of the above principles. The presence of both elements creates an overlapping of permutation possibilities.

• The total number of unique sequences is addressed by adding constraints to consider both factors simultaneously.

Example Analysis

Suppose you are evaluating a potential run in a modified Rummy deck: • 2 Wildcards (`W = 2`) • Maximum duplicates per rank and suit (`D = 2`) • Focus on 4-card runs (`n = 4`)

Calculate potential valid runs:

  1. Without any wildcards or duplicates, possible runs: (13−4+11)⋅(41)=10⋅4=40\binom{13-4+1}{1} \cdot \binom{4}{1} = 10 \cdot 4 = 40 distinct runs per suit.
  2. Considering wildcards: With 2 wildcards, capable of filling any position, additional runs generated as ∑k=12(4k)⋅(13−k4−k)\sum_{k=1}^{2} \binom{4}{k} \cdot \binom{13-k}{4-k}.
  3. Considering duplicates: Each existing permutation has `2^4 = 16` variations due to duplicates.

Combining these calculations delivers a comprehensive look at all potential hand configurations.

Comprehensive Summary Table

AspectCalculationDescription
Base Runs (No Mods)(R−n+11)⋅S\binom{R-n+1}{1} \cdot SDetermines base sequences per suit
Wildcards Influence∑k=0W(nk)⋅(R−kn−k)\sum_{k=0}^{W} \binom{n}{k} \cdot \binom{R-k}{n-k}Adjust sequences considering flexible positions
Duplicates Influence(Rn)⋅Dn\binom{R}{n} \cdot D^nAccounts for multiple identical cards per rank
Combination ComplexityFactors both wildcards and duplicatesOverlap of combinatorial possibilities
Total Hand Evaluation

Exploring the combinatorics of card games with runs, wildcards, and duplicates showcases the intricate interactivities and rich problem space within card-based combinatorics. Such an analysis is not only applicable to game design but also extends to probability theory, enriching understanding in statistics and beyond.


Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms