### Install Eval7 from source after cloning Source: https://github.com/julianandrews/pyeval7/blob/master/README.rst This snippet outlines the installation process for eval7 after cloning the repository. It requires Cython to be installed first, and then uses `setup.py` to install the library. ```bash python setup.py install ``` -------------------------------- ### Install Eval7 using pip Source: https://github.com/julianandrews/pyeval7/blob/master/README.rst This snippet shows the standard pip installation command for the eval7 library. It assumes that binary wheel packages are available for the user's Python version on PyPI. ```bash pip install eval7 ``` -------------------------------- ### Install Cython for Eval7 Source: https://github.com/julianandrews/pyeval7/blob/master/README.rst This command installs Cython, a necessary build dependency for eval7, especially when binary wheels are not available. It uses pip to fetch and install the package. ```bash pip install cython ``` -------------------------------- ### Eval7 Hand Evaluation with Specific Cards Source: https://github.com/julianandrews/pyeval7/blob/master/README.rst This example shows how to manually create a list of Card objects and evaluate a specific hand. It demonstrates evaluating a straight. ```python import eval7 hand = [eval7.Card(s) for s in ('As', '2c', '3d', '5s', '4c')] print(eval7.evaluate(hand)) print(eval7.handtype(eval7.evaluate(hand))) ``` -------------------------------- ### Eval7 HandRange Parsing: Basic Example Source: https://github.com/julianandrews/pyeval7/blob/master/README.rst Illustrates how to parse a PokerStove style hand range string using eval7. This example shows creating a HandRange object and accessing its parsed hands. ```python from pprint import pprint hr = eval7.HandRange("AQs+, 0.4(AsKs)") pprint(hr.hands) ``` -------------------------------- ### Basic Eval7 Usage: Dealing and Evaluating a Hand Source: https://github.com/julianandrews/pyeval7/blob/master/README.rst Demonstrates the fundamental usage of the eval7 library. It shows how to create a deck, shuffle it, deal a hand of 7 cards, and then evaluate the hand's strength and determine its type. ```python import eval7, pprint deck = eval7.Deck() deck.shuffle() hand = deck.deal(7) pprint.pprint(hand) print(eval7.evaluate(hand)) print(eval7.handtype(eval7.evaluate(hand))) ``` -------------------------------- ### Preflop Equity Calculation with Monte Carlo Source: https://context7.com/julianandrews/pyeval7/llms.txt Calculates preflop equity for a given hand against a villain's hand range using Monte Carlo simulation. The number of iterations can be adjusted to balance accuracy and speed. Dependencies include the eval7 library. ```python import eval7 hand = tuple(map(eval7.Card, ("As", "Ad"))) villain = eval7.HandRange("AA, A3o, 32s") board = [] equity = eval7.py_hand_vs_range_monte_carlo(hand, villain, board, 1000000) print(f"Preflop equity: {equity:.2%}") # ~85.34% ``` ```python import eval7 hand = tuple(map(eval7.Card, ("Ah", "Kh"))) villain = eval7.HandRange("JJ+, AK, AQ") board = tuple(map(eval7.Card, ("Qh", "Jh", "2c"))) equity = eval7.py_hand_vs_range_monte_carlo(hand, villain, board, 500000) print(f"Flop equity with flush draw: {equity:.2%}") ``` ```python import eval7 hand = tuple(map(eval7.Card, ("9s", "8s"))) villain = eval7.HandRange("AA-JJ, AK") board = tuple(map(eval7.Card, ("Th", "7d", "2c", "Jh"))) equity = eval7.py_hand_vs_range_monte_carlo(hand, villain, board, 500000) print(f"Turn equity with straight: {equity:.2%}") ``` ```python import eval7 iterations_test = [10000, 100000, 1000000] hand = tuple(map(eval7.Card, ("Ks", "Qh"))) villain = eval7.HandRange("77+, ATs+, KTs+, QTs+, AJo+, KQo") board = [] for iters in iterations_test: equity = eval7.py_hand_vs_range_monte_carlo(hand, villain, board, iters) print(f"{iters:7d} iterations: {equity:.4f}") ``` -------------------------------- ### Simulate with a 52-Card Deck using eval7.Deck Source: https://context7.com/julianandrews/pyeval7/llms.txt Provides a full 52-card deck object with methods for common card simulation tasks like shuffling, dealing, peeking, and sampling. The deck maintains its state throughout operations. Useful for creating realistic poker simulations and managing card distribution. ```python import eval7 # Create and shuffle a deck deck = eval7.Deck() print(f"Deck size: {len(deck)}") # 52 deck.shuffle() ``` -------------------------------- ### Deal Cards from a Deck Source: https://context7.com/julianandrews/pyeval7/llms.txt Demonstrates dealing a specific number of cards from a shuffled deck, peeking at the top cards without removing them, and sampling random cards. It also shows a full simulation of a poker hand including dealing hole cards, the flop, turn, and river, followed by evaluating the hands and determining the winner. This functionality is core to simulating poker games. ```python import eval7 # Initialize and shuffle a deck deck = eval7.Deck() deck.shuffle() # Deal a 7-card hand hand = deck.deal(7) print(f"Hand: {hand}") print(f"Remaining cards: {len(deck)}") # Peek at top cards without removing them top_cards = deck.peek(3) print(f"Top 3 cards: {top_cards}") print(f"Deck size unchanged: {len(deck)}") # Sample random cards without altering deck random_cards = deck.sample(5) print(f"Random sample: {random_cards}") print(f"Deck size still: {len(deck)}") # Full simulation example deck = eval7.Deck() deck.shuffle() hero_hand = deck.deal(2) villain_hand = deck.deal(2) flop = deck.deal(3) turn = deck.deal(1) river = deck.deal(1) hero_full = hero_hand + flop + turn + river villain_full = villain_hand + flop + turn + river hero_value = eval7.evaluate(hero_full) villain_value = eval7.evaluate(villain_full) print(f"Hero: {hero_hand} -> {eval7.handtype(hero_value)}") print(f"Villain: {villain_hand} -> {eval7.handtype(villain_value)}") print(f"Winner: {'Hero' if hero_value > villain_value else 'Villain' if villain_value > hero_value else 'Tie'}") ``` -------------------------------- ### Create Individual Playing Cards with eval7.Card Source: https://context7.com/julianandrews/pyeval7/llms.txt Represents a single playing card with rank and suit. Cards are initialized from two-character strings (e.g., 'As' for Ace of Spades). Supports comparison and can be used to construct hands for evaluation. Properties like rank and suit index are accessible. ```python import eval7 # Create individual cards ace_of_spades = eval7.Card("As") king_of_hearts = eval7.Card("Kh") two_of_clubs = eval7.Card("2c") print(ace_of_spades) # As print(repr(ace_of_spades)) # Card("As") # Cards can be compared print(ace_of_spades == eval7.Card("As")) # True print(ace_of_spades == king_of_hearts) # False # Create a hand from card strings hand = [eval7.Card(s) for s in ('Ac', 'Kd', 'Qh', 'Js', 'Tc')] value = eval7.evaluate(hand) print(f"{eval7.handtype(value)}") # Straight # Access card properties print(f"Rank index: {ace_of_spades.rank}") # 12 (A is highest) print(f"Suit index: {ace_of_spades.suit}") # 3 (spades) print(f"Available ranks: {eval7.ranks}") # ('2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A') print(f"Available suits: {eval7.suits}") # ('c', 'd', 'h', 's') ``` -------------------------------- ### Calculate Exact Hand vs. Range Equity Source: https://context7.com/julianandrews/pyeval7/llms.txt Provides functionality for exact equity calculation of a specific hand against a range on a complete 5-card board. This method enumerates all possible opponent hands and performs direct comparisons. It is suitable for completed boards and heads-up, unweighted scenarios. Card removal effects are handled automatically. ```python import eval7 # Exact equity with completed board hand = tuple(map(eval7.Card, ("Ac", "Ah"))) villain = eval7.HandRange("AA") board = tuple(map(eval7.Card, ("Kh", "Jd", "8c", "5d", "2s"))) equity = eval7.py_hand_vs_range_exact(hand, villain, board) print(f"Equity: {equity:.2%}") # Against multiple hand types in range hand = tuple(map(eval7.Card, ("As", "Ad"))) villain = eval7.HandRange("AA, A3o, 32s") board = tuple(map(eval7.Card, ("Kh", "Jd", "8c", "5d", "2s"))) equity = eval7.py_hand_vs_range_exact(hand, villain, board) print(f"Equity against range: {equity:.2%}") # Equity with different board textures test_cases = [ ("Ac", "Ah", "KK+", ("Kh", "Jd", "8c", "5d", "2s")), ("9s", "9h", "88-JJ", ("9d", "5h", "2c", "Qd", "Ks")), ("Ah", "Kh", "AQo+", ("Qh", "Jh", "Th", "2c", "3d")), ] for h1, h2, range_str, board_strs in test_cases: hand = tuple(map(eval7.Card, (h1, h2))) villain = eval7.HandRange(range_str) board = tuple(map(eval7.Card, board_strs)) equity = eval7.py_hand_vs_range_exact(hand, villain, board) print(f"{h1}{h2} vs {range_str}: {equity:.2%}") ``` -------------------------------- ### Perform Monte Carlo Equity Calculation Source: https://context7.com/julianandrews/pyeval7/llms.txt Offers approximate equity calculation using Monte Carlo simulations for incomplete boards (preflop, flop, turn). It takes a hand, opponent range, current board, and the number of iterations. This function is ideal for dynamic scenarios where not all cards are known, providing estimated equity with adjustable accuracy and computation time. ```python import eval7 # Monte Carlo equity calculation for incomplete boards # Example: Preflop equity hand = tuple(map(eval7.Card, ("As", "Kc"))) villain_range = eval7.HandRange("TT+, AJs+, KQs, AQo+") board = () iterations = 10000 equity = eval7.py_hand_vs_range_monte_carlo(hand, villain_range, board, iterations) print(f"Preflop Equity: {equity:.2%}") # Example: Flop equity hand = tuple(map(eval7.Card, ("Ah", "Ad"))) villain_range = eval7.HandRange("AA, KK, QQ, JJ, TT, AKs, AKo, AQs, AQo") board = tuple(map(eval7.Card, ("Kh", "Qh", "5s"))) iterations = 10000 equity = eval7.py_hand_vs_range_monte_carlo(hand, villain_range, board, iterations) print(f"Flop Equity: {equity:.2%}") ``` -------------------------------- ### Calculate Equity for Multiple Hands vs. Range Source: https://context7.com/julianandrews/pyeval7/llms.txt Calculates equity for every hand in a hero range against a villain range. Returns a dictionary mapping hero hands to their equity values. It automatically uses exact calculations when efficient or Monte Carlo otherwise. Supports only unweighted ranges and heads-up scenarios. Dependencies: eval7 library. ```python import eval7 # Calculate equity for entire range vs range hero = eval7.HandRange("AsAd, 3h2c, KsQs") villain = eval7.HandRange("AA, A3o, 32s") board = [] equity_map = eval7.py_all_hands_vs_range(hero, villain, board, 1000000) for hand, equity in sorted(equity_map.items(), key=lambda x: x[1], reverse=True): print(f"{hand[0]}{hand[1]}: {equity:.2%}") # Output: AsAd: 85.34%, KsQs: 44.12%, 3h2c: 22.87% ``` ```python import eval7 # Range vs range on a flop hero = eval7.HandRange("JJ+, AK") villain = eval7.HandRange("88-TT, AQ, KQ") board = tuple(map(eval7.Card, ("Qh", "9d", "5c"))) equity_map = eval7.py_all_hands_vs_range(hero, villain, board, 500000) print(f"Hero has {len(equity_map)} viable hands") avg_equity = sum(equity_map.values()) / len(equity_map) print(f"Average hero equity: {avg_equity:.2%}") ``` ```python import eval7 # Handle impossible hands (card removal) hero = eval7.HandRange("JsJc, QsJs") villain = eval7.HandRange("JJ") board = tuple(map(eval7.Card, ("Kh", "Jd", "8c"))) equity_map = eval7.py_all_hands_vs_range(hero, villain, board, 500000) print(f"Viable hands after card removal: {len(equity_map)}") # Only 1 (JsJc impossible) for hand, equity in equity_map.items(): print(f"{hand[0]}{hand[1]}: {equity:.2%}") ``` ```python import eval7 # Full preflop range analysis hero_range = "99+, AJs+, KQs, AQo+" villain_range = "66-TT, A9s+, KTs+, QTs+, JTs, AJo+, KQo" hero = eval7.HandRange(hero_range) villain = eval7.HandRange(villain_range) board = [] equity_map = eval7.py_all_hands_vs_range(hero, villain, board, 100000) # Find best and worst hands in hero range best_hand = max(equity_map.items(), key=lambda x: x[1]) worst_hand = min(equity_map.items(), key=lambda x: x[1]) print(f"Best: {best_hand[0][0]}{best_hand[0][1]} at {best_hand[1]:.2%}") print(f"Worst: {worst_hand[0][0]}{worst_hand[0][1]} at {worst_hand[1]:.2%}") ``` -------------------------------- ### Parse Poker Hand Ranges Source: https://context7.com/julianandrews/pyeval7/llms.txt Explains how to parse PokerStove-style hand range strings into enumerated hand combinations. It supports various notations including suited, offsuit, pairs, and weighted ranges. Each hand is represented as a tuple of Card objects with a weight. This is useful for defining opponent strategies or analyzing hand frequencies. ```python import eval7 from pprint import pprint # Simple range with suited and pair combinations hr = eval7.HandRange("AQs+, 0.4(AsKs)") print(f"Total combinations: {len(hr)}") pprint(hr.hands[:3]) # Complex range with pairs, suited, and weighted combos hr = eval7.HandRange("AJ+, ATs, KQ+, 33-JJ, 0.8(QQ+, KJs)") print(f"Total combinations: {len(hr)}") # Iterate over range for hand, weight in hr: if weight < 1.0: print(f"{hand}: {weight}") # Common range patterns ranges = { "tight_open": "88+, ATs+, KJs+, QJs, AJo+, KQo", "3bet": "JJ+, AQs+, AKo", "cold_call": "77-JJ, ATs-AQs, KTs+, QTs+, JTs, 98s, AJo+, KQo", "button_open": "22+, A2s+, K2s+, Q8s+, J8s+, T8s+, 97s+, 86s+, 76s, 65s, A9o+, K9o+, Q9o+, J9o+, T9o", } for name, range_str in ranges.items(): hr = eval7.HandRange(range_str) print(f"{name}: {len(hr)} combinations") # Weighted range example hr = eval7.HandRange("AA, 0.5(KK), 0.25(AKs)") total_weight = sum(weight for hand, weight in hr) print(f"Total weighted combinations: {total_weight}") ``` -------------------------------- ### Eval7 HandRange Parsing: Counting Hands Source: https://github.com/julianandrews/pyeval7/blob/master/README.rst Demonstrates parsing a more complex hand range string and then checking the total number of unique hands represented by that range. ```python hr = eval7.HandRange("AJ+, ATs, KQ+, 33-JJ, 0.8(QQ+, KJs)") print(len(hr)) ``` -------------------------------- ### Evaluate Poker Hand Strength using eval7 Source: https://context7.com/julianandrews/pyeval7/llms.txt Evaluates a 5-7 card poker hand, returning a numeric score representing its strength. Higher scores indicate stronger hands. Accepts a sequence of Card objects and can be converted to a hand type name using the handtype function. Supports comparing hands and identifying specific hand types like straights. ```python import eval7 # Evaluate a 7-card hand hand = [eval7.Card(s) for s in ('As', 'Ah', 'Kd', 'Qc', 'Jh', '9s', '2c')] value = eval7.evaluate(hand) print(f"Hand value: {value}") # Hand value: 35676160 print(f"Hand type: {eval7.handtype(value)}") # Hand type: Pair # Compare two hands hand1 = [eval7.Card(s) for s in ('As', 'Ah', 'Kd', 'Qc', 'Jh')] hand2 = [eval7.Card(s) for s in ('Ks', 'Kh', 'Qd', 'Jc', 'Th')] value1 = eval7.evaluate(hand1) value2 = eval7.evaluate(hand2) if value1 > value2: print("Hand 1 wins") elif value2 > value1: print("Hand 2 wins") else: print("Tie") # Evaluate a straight straight = [eval7.Card(s) for s in ('As', '2c', '3d', '5s', '4c')] print(eval7.handtype(eval7.evaluate(straight))) # Straight ``` -------------------------------- ### Convert Numeric Hand Value to Hand Type Name with eval7 Source: https://context7.com/julianandrews/pyeval7/llms.txt Converts a numeric hand evaluation value obtained from eval7.evaluate() into a human-readable string. Returns one of the standard poker hand types: "High Card", "Pair", "Two Pair", "Trips", "Straight", "Flush", "Full House", "Quads", or "Straight Flush". Useful for displaying evaluation results clearly. ```python import eval7 # Get hand type from evaluation value cards = [eval7.Card(s) for s in ('2c', '3d', '4h', '4s', '7s', '7d', '9c')] value = eval7.evaluate(cards) hand_type = eval7.handtype(value) print(f"{hand_type}: {value}") # Two Pair: 33892096 # Identify different hand types test_hands = [ (['2c', '3d', '4h', '5s', '7s', '8d', '9c'], 'High Card'), (['2c', '3d', '4h', '4s', '7s', '8d', '9c'], 'Pair'), (['2c', '3d', '4h', '7s', '7c', '7d', '9c'], 'Trips'), (['2c', '3h', '4h', '5s', 'Jh', '7h', '6h'], 'Flush'), (['Ac', 'Th', 'Ts', 'Ks', 'Kh', 'Kd'], 'Full House'), (['3c', '2c', '5c', 'Ac', '4c', 'Kc'], 'Straight Flush'), ] for card_strs, expected_type in test_hands: cards = [eval7.Card(s) for s in card_strs] value = eval7.evaluate(cards) actual_type = eval7.handtype(value) assert actual_type == expected_type, f"Expected {expected_type}, got {actual_type}" print(f"✓ {expected_type}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.