A sophisticated Texas Hold'em poker probability calculator implemented in Rust that calculates hand probabilities and winning odds in real-time.
- Calculate probabilities for all possible poker hand categories
- Compute winning probability against multiple opponents
- Support for multiple card decks
- Real-time probability updates at each stage (pre-flop, flop, turn, river)
- Hand strength percentile ranking
- Monte Carlo simulation for accurate probability estimation
-
Card Representation (
card.rs)- Cards are represented with a unique ID (0-51)
- Each card has a rank (2-A) and suit (clubs, diamonds, hearts, spades)
- Conversion methods between string representation ("Ah" for Ace of hearts) and internal ID
-
Hand Evaluation (
evaluator7.rs)- Uses a 7-card evaluator to determine hand strength
- Returns a rank between 1 and 7462 (1 being the best possible hand)
- Ranks are converted to standard poker hand categories (Straight Flush, Four of a Kind, etc.)
-
Probability Calculation (
probability.rs)- Uses Monte Carlo simulation with 10,000 iterations
- Two main probability calculations:
- Hand category probabilities
- Winning probabilities against opponents
- Creates a deck excluding known cards (hole cards + community cards)
- For each simulation:
- Shuffles remaining deck
- Completes community cards to 5 if needed
- Evaluates resulting 7-card hand
- Records hand category
- Converts counts to percentages
- Creates a deck excluding known cards
- For each simulation:
- Shuffles deck
- Deals random hole cards to opponents
- Completes community cards
- Evaluates all hands
- Compares player's hand against opponents
- Calculates win percentage
Hands are ranked in standard poker order (from highest to lowest):
- Royal Flush (special case of Straight Flush)
- Straight Flush
- Four of a Kind
- Full House
- Flush
- Straight
- Three of a Kind
- Two Pair
- One Pair
- High Card
- Converts raw rank (1-7462) to percentile (0-100%)
- Formula: ((7462 - rank) / 7462) * 100
- Higher percentile indicates stronger hand
- Example: Rank 1 = 100th percentile, Rank 7462 = 0th percentile
- Run the program
- Enter number of players
- Enter number of card decks
- Input hole cards using card numbers (displayed on screen)
- Optionally input community cards as they appear:
- Flop (3 cards)
- Turn (1 card)
- River (1 card)
The program will display:
- Current hand probabilities for each category
- Win probability against specified number of opponents
- Hand strength percentile when 5 or more cards are available
- Default 10,000 iterations for balance of accuracy and speed
- Configurable through
NUM_SIMULATIONSconstant - Higher iterations increase accuracy but decrease performance
- Supports multiple decks
- Automatically removes dealt cards from deck
- Prevents duplicate cards in simulations
- Efficient card representation using integer IDs
- Fast hand evaluation using pre-computed lookup tables
- Memory-efficient data structures
- Parallel simulation capability (future enhancement)
Card: Represents a playing card with an IDRankCategory: Enum of poker hand categoriesHashMap<RankCategory, f64>: Stores category probabilities
calculate_hand_probabilities: Computes probabilities for each hand categorycalculate_win_probability: Determines chances of winning against opponentsget_ordered_probabilities: Returns probabilities in standard poker hand orderevaluate_7cards: Evaluates strength of a 7-card poker hand
- Input validation for card numbers
- Deck overflow prevention
- Invalid hand detection
- Proper error messages for user guidance
- Parallel processing for faster simulations
- GUI interface
- Hand history tracking
- Opponent modeling
- Pot odds calculator
- Tournament mode