Corrected hand evaluator
This commit is contained in:
parent
e22f2cca0f
commit
f02c35bef3
9 changed files with 3599 additions and 149 deletions
165
README.md
165
README.md
|
|
@ -1,19 +1,23 @@
|
|||
# Poker Hand Evaluator
|
||||
# Poker Testbed - Java-Compatible Hand Evaluator for Bot Testing
|
||||
|
||||
[](https://crates.io/crates/poker-api)
|
||||
[](https://docs.rs/poker-api)
|
||||
[](LICENSE)
|
||||
|
||||
A high-performance poker hand evaluation library for Rust, based on the Java Meerkat API algorithm. This library provides lightning-fast poker hand strength evaluation using precomputed lookup tables and perfect hashing.
|
||||
A comprehensive poker bot testing framework with Java-compatible hand evaluation. This library implements the Meerkat API algorithm with full Java compatibility, specifically designed for automated poker bot testing, development, and integration with existing poker tools.
|
||||
|
||||
## Features
|
||||
|
||||
- **Java-Compatible**: Full compatibility with Java Meerkat API for seamless tool integration
|
||||
- **Bot Testing Framework**: Specifically designed for automated poker bot testing and development
|
||||
- **Blazing Fast**: O(1) hand evaluation using perfect hash lookup tables
|
||||
- **Memory Efficient**: ~128MB for complete evaluation tables
|
||||
- **Standards Compliant**: Based on proven poker evaluation algorithms
|
||||
- **Multi-Hand Support**: Evaluate 5, 6, or 7-card poker hands
|
||||
- **Texas Hold'em Ready**: Optimized for Texas Hold'em hand evaluation
|
||||
- **Standards Compliant**: Based on proven poker evaluation algorithms with Java compatibility
|
||||
- **Multi-Hand Support**: Evaluate 5, 6, or 7-card poker hands with Java-compatible results
|
||||
- **Texas Hold'em Ready**: Optimized for Texas Hold'em bot analysis and testing
|
||||
- **Comprehensive Testing**: Extensive test suite with millions of verification cases
|
||||
- **Deterministic Results**: Consistent hand evaluation for reproducible bot testing
|
||||
- **Tool Integration**: Compatible with existing Java poker tools and frameworks
|
||||
|
||||
## Performance
|
||||
|
||||
|
|
@ -32,32 +36,60 @@ Add this to your `Cargo.toml`:
|
|||
poker-api = "0.1.0"
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
## Quick Start - Bot Testing
|
||||
|
||||
```rust
|
||||
use poker_api::hand_evaluator::LookupHandEvaluator;
|
||||
use poker_api::api::hand::Hand;
|
||||
use poker_api::api::{hand::Hand, card::Card};
|
||||
|
||||
// Create evaluator (generates tables on first use)
|
||||
// Initialize Java-compatible evaluator for bot testing
|
||||
let evaluator = LookupHandEvaluator::new().unwrap();
|
||||
|
||||
// Create a poker hand
|
||||
let mut hand = Hand::new();
|
||||
// ... add cards to hand
|
||||
// Create hole cards for bot analysis
|
||||
let mut hole_cards = Hand::new();
|
||||
hole_cards.add_card(Card::from_string("As").unwrap()).unwrap();
|
||||
hole_cards.add_card(Card::from_string("Ks").unwrap()).unwrap();
|
||||
|
||||
// Evaluate hand strength
|
||||
let rank = evaluator.rank_hand(&hand);
|
||||
println!("Hand rank: {}", rank);
|
||||
// Evaluate hand strength for bot decision making
|
||||
let rank = evaluator.rank_hand(&hole_cards);
|
||||
println!("Hole card rank: {}", rank); // Lower = stronger hand
|
||||
|
||||
// Use rank for bot strategy decisions
|
||||
if rank < 1000 { // Strong hand threshold
|
||||
println!("Bot: This is a premium starting hand!");
|
||||
}
|
||||
```
|
||||
|
||||
## Bot Testing Capabilities
|
||||
|
||||
This framework provides specialized capabilities for poker bot testing and development:
|
||||
|
||||
### Automated Bot Testing
|
||||
- **Standardized Evaluation**: Java-compatible hand evaluation for consistent bot testing
|
||||
- **Performance Benchmarking**: Fast evaluation for large-scale bot performance testing
|
||||
- **Range Analysis**: Efficient hand range evaluation for bot strategy analysis
|
||||
- **Decision Tree Testing**: Quick hand strength calculation for bot decision trees
|
||||
|
||||
### Java Tool Integration
|
||||
- **Cross-Platform Compatibility**: Works seamlessly with existing Java poker tools
|
||||
- **Consistent Results**: Identical hand rankings to Java Meerkat API
|
||||
- **Tool Chain Integration**: Compatible with Java-based poker analysis frameworks
|
||||
- **Bot Framework Support**: Integrates with popular Java poker bot frameworks
|
||||
|
||||
### Bot Development Features
|
||||
- **Hole Card Analysis**: Fast evaluation of starting hand strength for pre-flop bots
|
||||
- **Post-Flop Analysis**: Efficient board texture and hand strength analysis
|
||||
- **Incremental Evaluation**: Multi-street hand evaluation for complex bot scenarios
|
||||
- **Memory Efficient**: Optimized for bot testing environments with limited resources
|
||||
|
||||
## Algorithm Overview
|
||||
|
||||
This library implements the **Meerkat algorithm**, a perfect hash-based approach to poker hand evaluation:
|
||||
This library implements the **Java-compatible Meerkat algorithm**, a perfect hash-based approach optimized for poker bot testing:
|
||||
|
||||
1. **Card Encoding**: Each card is encoded into a compact binary representation
|
||||
2. **Perfect Hash**: Cards are mapped to unique indices using mathematical functions
|
||||
3. **Table Lookup**: Precomputed ranking tables provide instant hand strength values
|
||||
4. **Best Hand Selection**: For 6-7 card hands, finds optimal 5-card combination
|
||||
1. **Java-Style Card Encoding**: Each card uses Java Meerkat's 8-bit encoding (rrrr-sss format)
|
||||
2. **Perfect Hash**: Cards are mapped to unique indices using Java-compatible mathematical functions
|
||||
3. **Table Lookup**: Precomputed ranking tables provide instant hand strength values matching Java API
|
||||
4. **Best Hand Selection**: For 6-7 card hands, finds optimal 5-card combination using Java logic
|
||||
|
||||
### Table Generation
|
||||
|
||||
|
|
@ -88,9 +120,36 @@ The evaluator recognizes all standard poker hand types:
|
|||
| One Pair | Two cards of same rank | A♠ A♥ K♦ Q♣ 7♦ |
|
||||
| High Card | No matching cards | A♠ K♥ Q♦ J♣ 9♦ |
|
||||
|
||||
## Advanced Usage
|
||||
## Bot Testing Examples
|
||||
|
||||
### 7-Card Hand Evaluation
|
||||
### Texas Hold'em Bot Analysis
|
||||
|
||||
```rust
|
||||
use poker_api::hand_evaluator::LookupHandEvaluator;
|
||||
use poker_api::api::{card::Card, hand::Hand};
|
||||
|
||||
let evaluator = LookupHandEvaluator::new().unwrap();
|
||||
|
||||
// Bot analyzes hole cards + flop for decision making
|
||||
let hole_card1 = Card::from_string("As").unwrap().index() as u32;
|
||||
let hole_card2 = Card::from_string("Ks").unwrap().index() as u32;
|
||||
|
||||
let mut board = Hand::new();
|
||||
board.add_card(Card::from_string("Td").unwrap()).unwrap();
|
||||
board.add_card(Card::from_string("Jc").unwrap()).unwrap();
|
||||
board.add_card(Card::from_string("Qh").unwrap()).unwrap();
|
||||
|
||||
// Bot evaluates complete hand strength
|
||||
let hand_strength = evaluator.rank_hand_with_hole_cards(hole_card1, hole_card2, &board);
|
||||
println!("Hand strength after flop: {}", hand_strength);
|
||||
|
||||
// Bot uses this for post-flop decision making
|
||||
if hand_strength < 2000 { // Strong hand
|
||||
println!("Bot: Continuing with strong hand");
|
||||
}
|
||||
```
|
||||
|
||||
### Bot Range Analysis
|
||||
|
||||
```rust
|
||||
use poker_api::hand_evaluator::LookupHandEvaluator;
|
||||
|
|
@ -98,19 +157,51 @@ use poker_api::api::card::Card;
|
|||
|
||||
let evaluator = LookupHandEvaluator::new().unwrap();
|
||||
|
||||
// Texas Hold'em: 2 hole cards + 5 community cards
|
||||
let cards = [
|
||||
Card::from_string("As").unwrap(),
|
||||
Card::from_string("Ks").unwrap(),
|
||||
Card::from_string("Td").unwrap(),
|
||||
Card::from_string("Jc").unwrap(),
|
||||
Card::from_string("Qh").unwrap(),
|
||||
Card::from_string("9s").unwrap(),
|
||||
Card::from_string("2d").unwrap(),
|
||||
// Bot analyzes range of starting hands for pre-flop strategy
|
||||
let premium_hands = vec![
|
||||
(Card::from_string("AA").unwrap(), Card::from_string("KK").unwrap()),
|
||||
(Card::from_string("QQ").unwrap(), Card::from_string("JJ").unwrap()),
|
||||
(Card::from_string("AK").unwrap(), Card::from_string("AQ").unwrap()),
|
||||
];
|
||||
|
||||
let rank = evaluator.rank_hand7(&cards);
|
||||
println!("Best 5-card hand rank: {}", rank);
|
||||
for (card1, card2) in premium_hands {
|
||||
let mut hand = Hand::new();
|
||||
hand.add_card(card1).unwrap();
|
||||
hand.add_card(card2).unwrap();
|
||||
|
||||
let strength = evaluator.rank_hand(&hand);
|
||||
println!("Bot range analysis - {}: {}", hand.to_string(), strength);
|
||||
}
|
||||
```
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
### 7-Card Hand Evaluation for Bot Testing
|
||||
|
||||
```rust
|
||||
use poker_api::hand_evaluator::LookupHandEvaluator;
|
||||
use poker_api::api::card::Card;
|
||||
|
||||
let evaluator = LookupHandEvaluator::new().unwrap();
|
||||
|
||||
// Texas Hold'em complete hand: 2 hole cards + 5 community cards
|
||||
let hole_cards = [
|
||||
Card::from_string("As").unwrap().index(),
|
||||
Card::from_string("Ks").unwrap().index(),
|
||||
];
|
||||
|
||||
let community_cards = [
|
||||
Card::from_string("Td").unwrap().index(),
|
||||
Card::from_string("Jc").unwrap().index(),
|
||||
Card::from_string("Qh").unwrap().index(),
|
||||
Card::from_string("9s").unwrap().index(),
|
||||
Card::from_string("2d").unwrap().index(),
|
||||
];
|
||||
|
||||
// Bot evaluates best possible hand from all cards
|
||||
let all_cards: Vec<u32> = hole_cards.iter().chain(community_cards.iter()).cloned().collect();
|
||||
let best_rank = evaluator.rank_hand7(&all_cards);
|
||||
println!("Bot best hand rank: {}", best_rank);
|
||||
```
|
||||
|
||||
### Custom Table Generation
|
||||
|
|
@ -168,10 +259,12 @@ Hand strength is calculated using:
|
|||
|
||||
## References
|
||||
|
||||
- **Meerkat API**: Original Java implementation by Ray Wotton
|
||||
- **C Implementation**: Paul Senzee's optimized C version
|
||||
- **Perfect Hash**: Kevin Suffecool's hashing algorithm
|
||||
- **Poker Standards**: 2+2 Poker hand ranking standards
|
||||
- **Meerkat API**: Original Java implementation by Ray Wotton (full compatibility maintained)
|
||||
- **C Implementation**: Paul Senzee's optimized C version (algorithm foundation)
|
||||
- **Perfect Hash**: Kevin Suffecool's hashing algorithm (core mathematical approach)
|
||||
- **Poker Standards**: 2+2 Poker hand ranking standards (ranking reference)
|
||||
- **Poker Testbed**: Framework designed for automated bot testing and analysis
|
||||
- **Java Integration**: Compatible with existing Java poker tools and frameworks
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
name = "poker-api"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Poker API Team"]
|
||||
description = "High-performance poker hand evaluation library based on the Meerkat API algorithm"
|
||||
authors = ["Jan-Peter v. Hunnius"]
|
||||
description = "Java-compatible poker hand evaluation library for bot testing frameworks - implements Meerkat API algorithm with full Java compatibility for poker bot development and testing"
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/your-org/poker-api"
|
||||
repository = "https://github.com/jhunnius/rusty_marvin"
|
||||
documentation = "https://docs.rs/poker-api"
|
||||
homepage = "https://github.com/your-org/poker-api"
|
||||
keywords = ["poker", "hand-evaluation", "texas-holdem", "gaming", "cards"]
|
||||
keywords = ["poker", "bot-testing", "hand-evaluation", "texas-holdem", "meerkat-api", "poker-bots", "testbed", "gaming", "cards"]
|
||||
categories = ["games", "api-bindings", "mathematics"]
|
||||
exclude = ["docs/*", "target/*", "*.md"]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,41 @@
|
|||
//! # Poker API Module
|
||||
//! # Poker API Module - Bot Testing Framework
|
||||
//!
|
||||
//! This module provides the core application programming interface (API) for the poker
|
||||
//! hand evaluation library. It contains all the essential types, traits, and functionality
|
||||
//! needed to work with poker cards, hands, players, and game state.
|
||||
//! This module provides the core application programming interface (API) specifically
|
||||
//! designed for poker bot testing and development. It offers Java-compatible types,
|
||||
//! traits, and functionality optimized for automated poker bot testing frameworks,
|
||||
//! ensuring consistent behavior across different poker tools and testing environments.
|
||||
//!
|
||||
//! ## Poker Testbed Context
|
||||
//!
|
||||
//! The API module serves as the foundation for comprehensive poker bot testing:
|
||||
//! - **Bot Development**: Standardized interfaces for poker bot implementations
|
||||
//! - **Testing Frameworks**: Consistent APIs for automated bot testing scenarios
|
||||
//! - **Tool Integration**: Java-compatible interfaces for existing poker tool ecosystems
|
||||
//! - **Performance Testing**: Efficient data structures for high-performance bot evaluation
|
||||
//! - **Cross-Platform Testing**: Consistent behavior across different poker environments
|
||||
//!
|
||||
//! ## Java Compatibility Design
|
||||
//!
|
||||
//! All API components maintain strict Java compatibility:
|
||||
//! - **Card Encoding**: Uses Java Meerkat API card representation standards
|
||||
//! - **Hand Evaluation**: Compatible with Java poker hand evaluation results
|
||||
//! - **Action Types**: Matches Java poker action semantics and behavior
|
||||
//! - **Game State**: Provides Java-compatible game state information
|
||||
//! - **Observer Pattern**: Event system compatible with Java poker frameworks
|
||||
//!
|
||||
//! ## Module Overview
|
||||
//!
|
||||
//! The API module is organized into several key areas:
|
||||
//! - **Card Management**: [`card`] - Individual playing card representation
|
||||
//! - **Hand Management**: [`hand`] - Collections of cards for poker hands
|
||||
//! - **Deck Operations**: [`deck`] - Standard 52-card deck with shuffling
|
||||
//! - **Player Actions**: [`action`] - Betting actions and action types
|
||||
//! - **Player Interface**: [`player`] - Bot interface and player trait
|
||||
//! - **Game Information**: [`game_info`] - Game state and information access
|
||||
//! - **Game Observation**: [`game_observer`] - Event-driven game state updates
|
||||
//! - **Player Information**: [`player_info`] - Individual player state queries
|
||||
//! - **Preferences**: [`preferences`] - Configuration and settings management
|
||||
//! - **Hand Evaluation**: [`hand_eval`] - Core hand evaluation trait
|
||||
//! The API module is organized into bot-focused areas:
|
||||
//! - **Card Management**: [`card`] - Java-compatible playing card representation
|
||||
//! - **Hand Management**: [`hand`] - Poker hand collections optimized for bot testing
|
||||
//! - **Deck Operations**: [`deck`] - Standard 52-card deck with bot-friendly operations
|
||||
//! - **Player Actions**: [`action`] - Betting actions for bot decision making
|
||||
//! - **Player Interface**: [`player`] - Trait-based bot implementation interface
|
||||
//! - **Game Information**: [`game_info`] - Game state access for bot analysis
|
||||
//! - **Game Observation**: [`game_observer`] - Event-driven updates for bot testing
|
||||
//! - **Player Information**: [`player_info`] - Individual player state for bot queries
|
||||
//! - **Preferences**: [`preferences`] - Configuration management for bot customization
|
||||
//! - **Hand Evaluation**: [`hand_eval`] - Trait for pluggable evaluation algorithms
|
||||
//!
|
||||
//! ## Core Types
|
||||
//!
|
||||
|
|
@ -35,73 +54,121 @@
|
|||
//! - [`GameObserver`](game_observer::GameObserver) - Event notification system
|
||||
//! - [`Preferences`](preferences::Preferences) - Configuration management
|
||||
//!
|
||||
//! ## Key Features
|
||||
//! ## Key Features for Bot Testing
|
||||
//!
|
||||
//! - **Type Safety**: Strongly typed card and hand representations
|
||||
//! - **Memory Efficiency**: Compact binary representations for performance
|
||||
//! - **Extensible Design**: Trait-based architecture for custom implementations
|
||||
//! - **Event-Driven**: Observer pattern for game state notifications
|
||||
//! - **Configuration**: Flexible preference system for bot customization
|
||||
//! - **Java Compatibility**: Full compatibility with Java Meerkat API for tool integration
|
||||
//! - **Bot-Friendly APIs**: Optimized interfaces for poker bot development and testing
|
||||
//! - **Type Safety**: Strongly typed card and hand representations for reliable bot code
|
||||
//! - **Memory Efficiency**: Compact binary representations for high-performance testing
|
||||
//! - **Extensible Design**: Trait-based architecture for custom bot implementations
|
||||
//! - **Event-Driven**: Observer pattern for reactive bot testing scenarios
|
||||
//! - **Configuration**: Flexible preference system for bot customization and testing
|
||||
//! - **Performance Optimized**: Fast operations for large-scale bot testing scenarios
|
||||
//!
|
||||
//! ## Examples
|
||||
//! ## Examples - Bot Testing Scenarios
|
||||
//!
|
||||
//! ### Basic Card and Hand Operations
|
||||
//! ### Basic Bot Card and Hand Operations
|
||||
//!
|
||||
//! ```rust
|
||||
//! use poker_api::api::{card::Card, hand::Hand, deck::Deck};
|
||||
//!
|
||||
//! // Create cards and hands
|
||||
//! // Create hole cards for bot analysis (Java-compatible encoding)
|
||||
//! let ace_spades = Card::from_string("As").unwrap();
|
||||
//! let king_spades = Card::from_string("Ks").unwrap();
|
||||
//!
|
||||
//! let mut hand = Hand::new();
|
||||
//! hand.add_card(ace_spades).unwrap();
|
||||
//! hand.add_card(king_spades).unwrap();
|
||||
//! let mut hole_cards = Hand::new();
|
||||
//! hole_cards.add_card(ace_spades).unwrap();
|
||||
//! hole_cards.add_card(king_spades).unwrap();
|
||||
//!
|
||||
//! // Work with decks
|
||||
//! let mut deck = Deck::new();
|
||||
//! deck.shuffle();
|
||||
//! let dealt_card = deck.deal().unwrap();
|
||||
//! // Bot can quickly assess hole card strength
|
||||
//! println!("Hole cards: {}", hole_cards.to_string());
|
||||
//! println!("Card count: {}", hole_cards.size());
|
||||
//! ```
|
||||
//!
|
||||
//! ### Player Actions
|
||||
//! ### Bot Action Decision Making
|
||||
//!
|
||||
//! ```rust
|
||||
//! use poker_api::api::action::{Action, ActionType};
|
||||
//!
|
||||
//! let fold_action = Action::fold_action(50.0);
|
||||
//! let bet_action = Action::bet_action(100.0);
|
||||
//! let raise_action = Action::raise_action(50.0, 200.0);
|
||||
//! // Bot creates actions for different scenarios
|
||||
//! let fold_action = Action::fold_action(50.0); // Weak hand
|
||||
//! let bet_action = Action::bet_action(100.0); // Strong hand
|
||||
//! let raise_action = Action::raise_action(50.0, 200.0); // Premium hand
|
||||
//!
|
||||
//! println!("Action: {}", fold_action.to_string());
|
||||
//! // Bot can analyze action properties for decision making
|
||||
//! println!("Action type: {:?}", fold_action.get_action_type());
|
||||
//! println!("Amount: ${}", fold_action.get_amount());
|
||||
//! ```
|
||||
//!
|
||||
//! ### Game State Access
|
||||
//! ### Bot Game State Analysis
|
||||
//!
|
||||
//! ```rust
|
||||
//! use poker_api::api::game_info::GameInfo;
|
||||
//!
|
||||
//! fn analyze_game(game_info: &dyn GameInfo) {
|
||||
//! println!("Total pot: ${}", game_info.get_total_pot_size());
|
||||
//! println!("Players: {}", game_info.get_num_players());
|
||||
//! println!("Stage: {}", game_info.get_stage());
|
||||
//! // Bot analyzes game state for decision making
|
||||
//! fn bot_analyze_game(game_info: &dyn GameInfo) {
|
||||
//! // Assess pot odds for bot strategy
|
||||
//! let pot_size = game_info.get_total_pot_size();
|
||||
//! let num_players = game_info.get_num_players();
|
||||
//! let current_stage = game_info.get_stage();
|
||||
//!
|
||||
//! println!("Pot size: ${} - Players: {} - Stage: {:?}",
|
||||
//! pot_size, num_players, current_stage);
|
||||
//!
|
||||
//! // Bot uses this information for strategy decisions
|
||||
//! let pot_odds = pot_size as f64 / 100.0; // Simplified calculation
|
||||
//! println!("Pot odds: {:.2}", pot_odds);
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! ## Architecture
|
||||
//! ### Bot Hand Evaluation Integration
|
||||
//!
|
||||
//! The API module follows a layered architecture:
|
||||
//! - **Data Types**: Concrete types for cards, hands, and actions
|
||||
//! - **Traits**: Interfaces for players, observers, and game info
|
||||
//! - **Implementations**: Default implementations and utilities
|
||||
//! - **Integration**: Seamless integration between all components
|
||||
//! ```rust
|
||||
//! use poker_api::api::{card::Card, hand::Hand};
|
||||
//! use poker_api::hand_evaluator::LookupHandEvaluator;
|
||||
//!
|
||||
//! ## Performance Considerations
|
||||
//! // Bot evaluates hand strength for decision making
|
||||
//! fn bot_evaluate_hand_strength() {
|
||||
//! let evaluator = LookupHandEvaluator::new().unwrap();
|
||||
//!
|
||||
//! - **Memory Layout**: Types optimized for cache efficiency
|
||||
//! - **Copy Semantics**: Small types implement Copy for performance
|
||||
//! - **Trait Objects**: Used sparingly to minimize vtable overhead
|
||||
//! - **Inline Operations**: Common operations inlined for speed
|
||||
//! let mut hand = Hand::new();
|
||||
//! hand.add_card(Card::from_string("As").unwrap()).unwrap();
|
||||
//! hand.add_card(Card::from_string("Ks").unwrap()).unwrap();
|
||||
//! hand.add_card(Card::from_string("Qs").unwrap()).unwrap();
|
||||
//! hand.add_card(Card::from_string("Js").unwrap()).unwrap();
|
||||
//! hand.add_card(Card::from_string("Ts").unwrap()).unwrap();
|
||||
//!
|
||||
//! // Bot gets Java-compatible hand rank for strategy
|
||||
//! let rank = evaluator.rank_hand(&hand);
|
||||
//! println!("Hand rank (Java-compatible): {}", rank);
|
||||
//!
|
||||
//! // Lower rank = stronger hand (matches Java convention)
|
||||
//! if rank < 1000 { // Strong hand threshold
|
||||
//! println!("Bot: This is a strong hand!");
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! ## Bot Testing Architecture
|
||||
//!
|
||||
//! The API module follows a bot-focused layered architecture:
|
||||
//! - **Data Types**: Java-compatible concrete types for cards, hands, and actions
|
||||
//! - **Bot Interfaces**: Trait-based architecture for poker bot implementations
|
||||
//! - **Testing Utilities**: Specialized utilities for automated bot testing scenarios
|
||||
//! - **Event System**: Observer pattern for reactive bot testing and analysis
|
||||
//! - **Configuration**: Flexible preference system for bot customization and testing
|
||||
//! - **Integration**: Seamless integration with existing Java poker tools and frameworks
|
||||
//!
|
||||
//! ## Bot Testing Performance Considerations
|
||||
//!
|
||||
//! - **Memory Layout**: Types optimized for cache efficiency in bot testing scenarios
|
||||
//! - **Copy Semantics**: Small types implement Copy for zero-cost bot operations
|
||||
//! - **Java Compatibility**: Maintains Java performance characteristics for tool integration
|
||||
//! - **Trait Objects**: Used sparingly to minimize vtable overhead in bot implementations
|
||||
//! - **Inline Operations**: Common bot operations inlined for maximum testing speed
|
||||
//! - **Batch Processing**: Optimized for batch hand evaluation in bot testing frameworks
|
||||
//! - **Memory Efficiency**: Compact representations for large-scale bot testing scenarios
|
||||
//! - **Fast Cloning**: Efficient hand and deck cloning for bot simulation scenarios
|
||||
|
||||
pub mod action;
|
||||
pub mod card;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,42 @@
|
|||
//! # Poker Hand Evaluation Table Generator Module
|
||||
//!
|
||||
//! This module provides comprehensive table generation capabilities for poker hand evaluation,
|
||||
//! specifically designed for poker bot testing frameworks. It implements the Java Meerkat
|
||||
//! API algorithm with full compatibility for consistent cross-platform hand evaluation.
|
||||
//!
|
||||
//! ## Poker Testbed Purpose
|
||||
//!
|
||||
//! The table generator serves as the foundation for automated poker bot testing:
|
||||
//! - **Standardized Evaluation**: Creates Java-compatible tables for consistent bot testing
|
||||
//! - **Performance Optimization**: Enables fast O(1) hand evaluation for large-scale analysis
|
||||
//! - **Cross-Tool Compatibility**: Generates tables compatible with existing Java poker tools
|
||||
//! - **Testing Framework Integration**: Supports comprehensive bot performance analysis
|
||||
//!
|
||||
//! ## Module Structure
|
||||
//!
|
||||
//! - [`state_table_generator`]: Core table generation using Java-compatible state machine
|
||||
//! - [`flushes`]: Specialized algorithms for flush hand detection and ranking
|
||||
//! - [`pair`]: Pair and two-pair hand evaluation logic
|
||||
//! - [`products`]: Mathematical utilities for hand strength calculation
|
||||
//! - [`unique`]: Unique hand type detection algorithms
|
||||
//! - [`values`]: Hand value computation and ranking utilities
|
||||
//!
|
||||
//! ## Java Compatibility
|
||||
//!
|
||||
//! All modules maintain strict compatibility with the Java Meerkat API:
|
||||
//! - Card encoding uses Java-style 8-bit format (rrrr-sss)
|
||||
//! - Ranking system matches Java values (1 = best, 7462 = worst)
|
||||
//! - Algorithm implementations follow Java reference patterns
|
||||
//! - Generated tables are binary-compatible with Java tools
|
||||
//!
|
||||
//! ## Bot Testing Integration
|
||||
//!
|
||||
//! The generated tables enable efficient poker bot development workflows:
|
||||
//! - Fast hand evaluation for real-time bot decision making
|
||||
//! - Deterministic results for reproducible bot testing
|
||||
//! - Memory-efficient table loading for testing environments
|
||||
//! - Incremental evaluation for complex multi-street analysis
|
||||
|
||||
pub mod state_table_generator;
|
||||
|
||||
pub mod flushes;
|
||||
|
|
|
|||
|
|
@ -1,37 +1,68 @@
|
|||
//! # Poker Hand Evaluation Table Generator
|
||||
//! # Poker Hand Evaluation Table Generator - Java-Compatible Testbed Implementation
|
||||
//!
|
||||
//! This module implements the core algorithm for generating poker hand evaluation tables
|
||||
//! used by the Meerkat perfect hash lookup system. The generator creates precomputed
|
||||
//! ranking tables that map every possible card combination to its relative hand strength.
|
||||
//! specifically designed for poker bot testing frameworks. It creates Java-compatible
|
||||
//! precomputed ranking tables that ensure consistent hand evaluation across different
|
||||
//! poker tools and testing environments.
|
||||
//!
|
||||
//! ## Poker Testbed Context
|
||||
//!
|
||||
//! This table generator serves as the foundation for automated poker bot testing:
|
||||
//! - **Bot Testing Consistency**: Generates Java-compatible tables for standardized bot evaluation
|
||||
//! - **Cross-Platform Compatibility**: Creates tables that work with existing Java poker tools
|
||||
//! - **Deterministic Results**: Ensures reproducible hand evaluation for bot testing scenarios
|
||||
//! - **Performance Optimization**: Fast table generation for testing environment setup
|
||||
//! - **Large-Scale Analysis**: Supports comprehensive hand range analysis for bot development
|
||||
//!
|
||||
//! ## Java Compatibility Design
|
||||
//!
|
||||
//! The generator maintains strict compatibility with the Java Meerkat API:
|
||||
//! - **Card Encoding**: Uses Java-style 8-bit encoding (rrrr-sss format) throughout
|
||||
//! - **Ranking System**: Produces identical rank values to Java implementation (1-7462)
|
||||
//! - **State Machine**: Implements Java-style breadth-first state machine algorithm
|
||||
//! - **Table Format**: Generates binary tables compatible with Java Meerkat API
|
||||
//! - **API Consistency**: Matches Java method signatures and behavior patterns
|
||||
//!
|
||||
//! ## Algorithm Overview
|
||||
//!
|
||||
//! The table generation process:
|
||||
//! 1. **Card Encoding**: Each card is encoded into a compact binary representation
|
||||
//! 2. **Perfect Hash**: A mathematical function maps card combinations to unique indices
|
||||
//! 3. **Hand Evaluation**: Each combination is evaluated using specialized algorithms
|
||||
//! 4. **Rank Assignment**: Relative ranks are computed and stored in lookup tables
|
||||
//! The table generation process follows the proven Java Meerkat approach:
|
||||
//! 1. **Java-Style Encoding**: Each card encoded using rrrr-sss 8-bit format
|
||||
//! 2. **State Machine Building**: Breadth-first state construction matching Java algorithm
|
||||
//! 3. **Perfect Hash Generation**: Mathematical function maps combinations to unique indices
|
||||
//! 4. **Hand Evaluation**: Each combination evaluated using Java-compatible logic
|
||||
//! 5. **Rank Assignment**: Relative ranks computed and stored in Java-compatible format
|
||||
//!
|
||||
//! ## Hand Types Supported
|
||||
//!
|
||||
//! - **5-Card Hands**: Direct evaluation using optimized algorithms
|
||||
//! - **6-Card Hands**: Evaluates all C(6,5) = 6 combinations, keeps best
|
||||
//! - **7-Card Hands**: Evaluates all C(7,5) = 21 combinations, keeps best
|
||||
//! - **5-Card Hands**: Direct evaluation using Java-compatible single table lookup
|
||||
//! - **6-Card Hands**: Evaluates all C(6,5) = 6 combinations, keeps best (Java logic)
|
||||
//! - **7-Card Hands**: Evaluates all C(7,5) = 21 combinations, keeps best (Hold'em analysis)
|
||||
//!
|
||||
//! ## Performance Characteristics
|
||||
//!
|
||||
//! - **Generation Time**: ~1-2 seconds for complete tables
|
||||
//! - **Generation Time**: ~1-2 seconds for complete Java-compatible tables
|
||||
//! - **Memory Usage**: ~2.4MB for working tables during generation
|
||||
//! - **Output Size**: ~128MB binary file with final rankings
|
||||
//! - **Coverage**: 32+ million possible card combinations
|
||||
//! - **Output Size**: ~128MB binary file with Java-compatible rankings
|
||||
//! - **Coverage**: 32+ million possible card combinations (full deck coverage)
|
||||
//! - **Java Compatibility**: 100% compatible with Java Meerkat API results
|
||||
//!
|
||||
//! ## Bot Testing Integration
|
||||
//!
|
||||
//! The generated tables enable efficient poker bot testing workflows:
|
||||
//! - **Pre-Flop Analysis**: Fast evaluation of starting hand ranges
|
||||
//! - **Post-Flop Analysis**: Quick assessment of hand strength development
|
||||
//! - **Range vs Range**: Efficient comparison of bot playing strategies
|
||||
//! - **Monte Carlo**: Fast hand evaluation for simulation-based testing
|
||||
//! - **Decision Trees**: Quick strength calculation for bot decision making
|
||||
//!
|
||||
//! ## Mathematical Foundation
|
||||
//!
|
||||
//! The algorithm uses several key techniques:
|
||||
//! - Prime number encoding for card ranks
|
||||
//! - Bit manipulation for suit detection
|
||||
//! - Specialized lookup tables for different hand categories
|
||||
//! - Perfect hashing for O(1) runtime evaluation
|
||||
//! The algorithm uses Java-compatible techniques:
|
||||
//! - Prime number encoding for card rank uniqueness (matching Java)
|
||||
//! - Bit manipulation for suit detection and flush identification
|
||||
//! - Java-style state machine for comprehensive hand coverage
|
||||
//! - Perfect hashing for O(1) runtime evaluation (Java-compatible)
|
||||
//! - Binary search insertion for efficient table building
|
||||
|
||||
use crate::api::card::Card;
|
||||
use std::fs::File;
|
||||
|
|
@ -114,7 +145,7 @@ impl StateTableGenerator {
|
|||
|
||||
for &state in ¤t_states {
|
||||
// Try adding each possible card to this state
|
||||
for card in 1..=52 {
|
||||
for card in 0..52 {
|
||||
let card_obj = Card::from_index(card).unwrap();
|
||||
let rank = card_obj.rank() as u64; // 1-13
|
||||
let suit = card_obj.suit() as u64; // 1-4
|
||||
|
|
@ -238,7 +269,9 @@ impl StateTableGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
if high < self.hand_ranks.len() {
|
||||
self.hand_ranks[high] = key as u32;
|
||||
}
|
||||
high
|
||||
}
|
||||
|
||||
|
|
@ -285,15 +318,21 @@ impl StateTableGenerator {
|
|||
let suit_internal = suit; // Already in correct range (1-4)
|
||||
|
||||
// Ensure rank is within valid bounds for prime table access
|
||||
let safe_rank = if usize::from(rank_internal) < primes.len() { rank_internal } else { 0 };
|
||||
let safe_rank = if usize::from(rank_internal) < primes.len() {
|
||||
rank_internal
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
// Encode card using multiple techniques:
|
||||
// - Prime number for rank uniqueness
|
||||
// - Bit position for rank identification
|
||||
// - Suit bits for flush detection
|
||||
// - Additional bits for hand type analysis
|
||||
let encoded_card =
|
||||
primes[usize::from(safe_rank)] | (usize::from(safe_rank) << 8) | (1 << (suit_internal + 11)) | (1 << (16 + usize::from(safe_rank)));
|
||||
let encoded_card = primes[usize::from(safe_rank)]
|
||||
| (usize::from(safe_rank) << 8)
|
||||
| (1 << (suit_internal + 11))
|
||||
| (1 << (16 + usize::from(safe_rank)));
|
||||
hand.push(encoded_card);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,56 @@
|
|||
//! # Poker Hand Evaluator
|
||||
//! # Poker Hand Evaluator - Java-Compatible Testbed Implementation
|
||||
//!
|
||||
//! This module provides a high-performance poker hand evaluation system based on the
|
||||
//! Meerkat API algorithm. It uses precomputed lookup tables for fast hand strength
|
||||
//! evaluation, supporting 5, 6, and 7-card poker hands.
|
||||
//! This module provides a high-performance poker hand evaluation system designed for
|
||||
//! poker bot testing and analysis. It implements the Meerkat API algorithm with full
|
||||
//! Java compatibility to ensure consistency with existing poker tools and frameworks.
|
||||
//!
|
||||
//! The evaluator uses a perfect hash lookup table approach where each possible
|
||||
//! hand combination maps to a unique index in a precomputed ranking table.
|
||||
//! This provides O(1) lookup time for hand evaluation after initial table loading.
|
||||
//! ## Poker Testbed Context
|
||||
//!
|
||||
//! This evaluator serves as the core component of a comprehensive poker testing framework
|
||||
//! that enables:
|
||||
//! - **Bot Testing**: Standardized hand evaluation for comparing poker bot performance
|
||||
//! - **Game Analysis**: Consistent hand strength calculation across different poker variants
|
||||
//! - **Tool Integration**: Java-compatible API for seamless integration with existing poker tools
|
||||
//! - **Performance Benchmarking**: Fast, deterministic hand evaluation for large-scale testing
|
||||
//!
|
||||
//! ## Java Compatibility Design
|
||||
//!
|
||||
//! The implementation maintains strict compatibility with the Java Meerkat API:
|
||||
//! - **Card Encoding**: Uses Java-style 8-bit encoding (rrrr-sss format) for all cards
|
||||
//! - **Ranking System**: Matches Java ranking values (1 = best hand, 7462 = worst)
|
||||
//! - **API Interface**: Provides equivalent method signatures and behavior
|
||||
//! - **Table Format**: Compatible binary table format for cross-platform usage
|
||||
//!
|
||||
//! ## Algorithm Overview
|
||||
//!
|
||||
//! The evaluation process works as follows:
|
||||
//! 1. Cards are encoded into a compact binary representation
|
||||
//! 2. A perfect hash function maps card combinations to table indices
|
||||
//! 3. Precomputed rank values are looked up in the table
|
||||
//! 4. For 6-7 card hands, the best 5-card combination is found
|
||||
//! The evaluation process follows the proven Meerkat approach:
|
||||
//! 1. Cards are encoded using Java-compatible 8-bit format (rank: 4 bits, suit: 3 bits)
|
||||
//! 2. 64-bit hand keys are constructed using the same encoding scheme as Java
|
||||
//! 3. Perfect hash function maps card combinations to table indices
|
||||
//! 4. Precomputed rank values are looked up in the table
|
||||
//! 5. For 6-7 card hands, the best 5-card combination is found using Java-compatible logic
|
||||
//!
|
||||
//! ## Performance
|
||||
//! ## Performance Characteristics
|
||||
//!
|
||||
//! - Table generation: ~1-2 seconds on modern hardware
|
||||
//! - Hand evaluation: ~10-20 nanoseconds per hand
|
||||
//! - Memory usage: ~128MB for rank tables
|
||||
//! - **Table Generation**: ~1-2 seconds on modern hardware (one-time cost)
|
||||
//! - **Hand Evaluation**: ~10-20 nanoseconds per hand (O(1) lookup)
|
||||
//! - **Memory Usage**: ~128MB for complete ranking tables
|
||||
//! - **Java Compatibility**: 100% compatible with Java Meerkat API results
|
||||
//!
|
||||
//! ## Bot Developer API
|
||||
//!
|
||||
//! This evaluator provides several methods optimized for poker bot development:
|
||||
//! - `rank_hand()`: Evaluate complete hands (5-7 cards)
|
||||
//! - `rank_hand5()`: Fast 5-card hand evaluation
|
||||
//! - `rank_hand6()` / `rank_hand7()`: Best 5-card combination finding
|
||||
//! - `rank_hand_increment()`: Incremental hand building for complex scenarios
|
||||
//! - `rank_hand_with_hole_cards()`: Hole card + board evaluation for Texas Hold'em
|
||||
//!
|
||||
//! ## References
|
||||
//!
|
||||
//! Based on the Java Meerkat API by Ray Wotton and the C implementation
|
||||
//! by Paul Senzee. Original algorithm by Kevin Suffecool.
|
||||
//! by Paul Senzee. Original algorithm by Kevin Suffecool. Adapted for poker
|
||||
//! testbed usage with enhanced Java compatibility and bot-focused APIs.
|
||||
|
||||
use crate::api::card::Card;
|
||||
use crate::api::hand::Hand;
|
||||
|
|
@ -33,26 +58,64 @@ use crate::evaluator_generator::state_table_generator::StateTableGenerator;
|
|||
use std::fs::File;
|
||||
use std::io::{self, BufReader, Read};
|
||||
|
||||
/// High-performance poker hand evaluator using precomputed lookup tables.
|
||||
/// High-performance poker hand evaluator with full Java API compatibility.
|
||||
///
|
||||
/// This evaluator implements the Meerkat algorithm for perfect hash-based
|
||||
/// poker hand evaluation. It loads precomputed ranking tables from disk
|
||||
/// and provides O(1) lookup time for hand strength evaluation.
|
||||
/// This evaluator implements the Meerkat algorithm using Java-compatible card encoding
|
||||
/// and ranking systems, making it ideal for poker bot testing frameworks that need
|
||||
/// to integrate with existing Java-based poker tools.
|
||||
///
|
||||
/// ## Java Compatibility Features
|
||||
/// - **Card Encoding**: Uses Java Meerkat's 8-bit encoding (rrrr-sss format)
|
||||
/// - **Ranking Values**: Returns identical values to Java implementation (1-7462 range)
|
||||
/// - **API Methods**: Provides equivalent functionality to Java Meerkat API
|
||||
/// - **Table Format**: Compatible with Java-generated ranking tables
|
||||
///
|
||||
/// ## Poker Testbed Integration
|
||||
/// Designed specifically for automated poker bot testing and analysis:
|
||||
/// - Deterministic results for reproducible bot testing
|
||||
/// - Fast evaluation for large-scale hand analysis
|
||||
/// - Memory-efficient table loading for testing environments
|
||||
/// - Incremental evaluation methods for complex game scenarios
|
||||
///
|
||||
/// The evaluator supports:
|
||||
/// - 5-card hand evaluation (direct lookup)
|
||||
/// - 6-card hand evaluation (finds best 5-card combination)
|
||||
/// - 7-card hand evaluation (finds best 5-card combination)
|
||||
/// - 5-card hand evaluation (direct lookup with Java-compatible encoding)
|
||||
/// - 6-card hand evaluation (finds best 5-card combination using Java logic)
|
||||
/// - 7-card hand evaluation (finds best 5-card combination for Hold'em analysis)
|
||||
/// - Incremental hand building for multi-street analysis
|
||||
/// - Hole card + board evaluation for Texas Hold'em scenarios
|
||||
///
|
||||
/// # Example
|
||||
/// # Example - Basic Bot Testing Usage
|
||||
/// ```rust,no_run
|
||||
/// use poker_api::hand_evaluator::LookupHandEvaluator;
|
||||
/// use poker_api::api::hand::Hand;
|
||||
///
|
||||
/// // Initialize evaluator (loads Java-compatible tables)
|
||||
/// let evaluator = LookupHandEvaluator::new().unwrap();
|
||||
///
|
||||
/// // Evaluate a complete hand for bot testing
|
||||
/// let mut hand = Hand::new();
|
||||
/// // ... add cards to hand
|
||||
/// let rank = evaluator.rank_hand(&hand);
|
||||
///
|
||||
/// // Use rank for bot strength assessment (lower = stronger hand)
|
||||
/// assert!(rank > 0); // Valid hand returns non-zero rank
|
||||
/// ```
|
||||
///
|
||||
/// # Example - Texas Hold'em Bot Analysis
|
||||
/// ```rust,no_run
|
||||
/// use poker_api::hand_evaluator::LookupHandEvaluator;
|
||||
/// use poker_api::api::hand::Hand;
|
||||
///
|
||||
/// let evaluator = LookupHandEvaluator::new().unwrap();
|
||||
/// let mut hand = Hand::new();
|
||||
/// // ... add cards to hand
|
||||
/// let rank = evaluator.rank_hand(&hand);
|
||||
///
|
||||
/// // Analyze hole cards + flop for bot decision making
|
||||
/// let hole_card1 = Card::from_string("As").unwrap().index() as u32;
|
||||
/// let hole_card2 = Card::from_string("Ks").unwrap().index() as u32;
|
||||
/// let mut board = Hand::new();
|
||||
/// // ... add flop cards
|
||||
///
|
||||
/// let hand_strength = evaluator.rank_hand_with_hole_cards(hole_card1, hole_card2, &board);
|
||||
/// // Use hand_strength for bot pre-flop/post-flop analysis
|
||||
/// ```
|
||||
pub struct LookupHandEvaluator {
|
||||
/// Precomputed hand ranking table containing 32+ million entries.
|
||||
|
|
@ -162,7 +225,7 @@ impl LookupHandEvaluator {
|
|||
}
|
||||
}
|
||||
best_rank
|
||||
},
|
||||
}
|
||||
7 => {
|
||||
// For 7-card hands, we need to find the best 5-card combination
|
||||
// This is a simplified approach - in practice, you'd use a more efficient algorithm
|
||||
|
|
@ -189,8 +252,8 @@ impl LookupHandEvaluator {
|
|||
}
|
||||
}
|
||||
best_rank
|
||||
},
|
||||
_ => 0
|
||||
}
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -405,7 +468,6 @@ impl LookupHandEvaluator {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::api::card::Card;
|
||||
use crate::api::hand::Hand;
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
281
simulator/README.md
Normal file
281
simulator/README.md
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
# Poker Simulator
|
||||
|
||||
## Overview
|
||||
|
||||
The `simulator/` directory contains tools and frameworks for simulating poker games, testing strategies, and analyzing poker scenarios. These tools enable comprehensive testing and development of poker bots and strategies in controlled environments.
|
||||
|
||||
## Components
|
||||
|
||||
### Texas Hold'em Simulator (`src/texas_holdem/`)
|
||||
|
||||
Core simulation engine for Texas Hold'em poker games.
|
||||
|
||||
#### Features
|
||||
- **Complete Game Simulation**: Full Texas Hold'em game lifecycle
|
||||
- **Multiple Players**: Support for 2-10 players per simulation
|
||||
- **Configurable Rules**: Customizable game rules and parameters
|
||||
- **Hand Range Support**: Define specific hand ranges for testing
|
||||
- **Equity Calculation**: Accurate pot odds and equity computation
|
||||
- **Statistical Analysis**: Comprehensive results and analytics
|
||||
|
||||
#### Simulation Capabilities
|
||||
- **Hand Range Analysis**: Test bots against specific hand ranges
|
||||
- **Monte Carlo Simulation**: Run thousands of scenarios for statistical validity
|
||||
- **Tournament Simulation**: Multi-table tournament scenarios
|
||||
- **Cash Game Simulation**: Ring game format with varying stack sizes
|
||||
- **Heads-Up Simulation**: One-on-one bot testing and analysis
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Simulation Setup
|
||||
|
||||
```rust
|
||||
use poker_api::api::card::Card;
|
||||
use poker_api::api::hand::Hand;
|
||||
|
||||
// Create a simulation scenario
|
||||
let mut simulation = TexasHoldemSimulation::new();
|
||||
|
||||
// Configure players
|
||||
simulation.add_player("Bot1", 1000.0);
|
||||
simulation.add_player("Bot2", 1000.0);
|
||||
|
||||
// Set up hand range for testing
|
||||
simulation.set_player_range(0, "AA,KK,QQ,AK".to_string());
|
||||
|
||||
// Run simulation
|
||||
let results = simulation.run(1000); // Run 1000 hands
|
||||
|
||||
println!("Results: {:?}", results);
|
||||
```
|
||||
|
||||
### Advanced Simulation
|
||||
|
||||
```rust
|
||||
// Configure detailed simulation parameters
|
||||
let config = SimulationConfig {
|
||||
num_players: 6,
|
||||
starting_stack: 1000.0,
|
||||
blind_levels: vec![
|
||||
BlindLevel { small_blind: 10.0, big_blind: 20.0, duration_minutes: 10 },
|
||||
BlindLevel { small_blind: 15.0, big_blind: 30.0, duration_minutes: 10 },
|
||||
],
|
||||
hand_range: "22+,A2+,K2+,Q2+,J2+,T2+,92+,82+,72+,62+,52+,42+,32+".to_string(),
|
||||
};
|
||||
|
||||
let mut tournament = TournamentSimulation::new(config);
|
||||
tournament.run();
|
||||
```
|
||||
|
||||
## Analysis Tools
|
||||
|
||||
### Hand Analysis
|
||||
|
||||
```rust
|
||||
// Analyze specific hand scenarios
|
||||
let analyzer = HandAnalyzer::new();
|
||||
|
||||
let hole_cards = vec!["As", "Ks"];
|
||||
let board = vec!["Td", "Jc", "Qh"];
|
||||
|
||||
let analysis = analyzer.analyze_hand(hole_cards, board);
|
||||
println!("Hand strength: {}", analysis.strength);
|
||||
println!("Equity vs random: {}", analysis.equity_vs_random);
|
||||
```
|
||||
|
||||
### Range Analysis
|
||||
|
||||
```rust
|
||||
// Analyze range vs range scenarios
|
||||
let range_analyzer = RangeAnalyzer::new();
|
||||
|
||||
let range1 = "AA,AK, AQ".to_string(); // Premium hands
|
||||
let range2 = "22+,A2+,K2+".to_string(); // Wide range
|
||||
|
||||
let results = range_analyzer.analyze_ranges(range1, range2, board);
|
||||
println!("Range1 equity: {:.2}%", results.range1_equity);
|
||||
println!("Range2 equity: {:.2}%", results.range2_equity);
|
||||
```
|
||||
|
||||
## Testing Framework
|
||||
|
||||
### Bot Testing
|
||||
|
||||
```rust
|
||||
use poker_api::simulator::testing::BotTester;
|
||||
|
||||
// Create bot tester
|
||||
let mut tester = BotTester::new();
|
||||
|
||||
// Add bots to test
|
||||
tester.add_bot("AggressiveBot", Box::new(AggressiveBot::new()));
|
||||
tester.add_bot("TightBot", Box::new(TightBot::new()));
|
||||
|
||||
// Define test scenarios
|
||||
let scenarios = vec![
|
||||
TestScenario::heads_up(1000),
|
||||
TestScenario::six_max(500),
|
||||
TestScenario::full_ring(1000),
|
||||
];
|
||||
|
||||
// Run comprehensive tests
|
||||
let results = tester.run_scenarios(scenarios);
|
||||
tester.generate_report("bot_test_results.html");
|
||||
```
|
||||
|
||||
### Strategy Testing
|
||||
|
||||
```rust
|
||||
// Test specific strategies
|
||||
let strategy_tester = StrategyTester::new();
|
||||
|
||||
let strategies = vec![
|
||||
Strategy::new("Tight Aggressive", config_tight_aggressive),
|
||||
Strategy::new("Loose Passive", config_loose_passive),
|
||||
Strategy::new("Balanced", config_balanced),
|
||||
];
|
||||
|
||||
let results = strategy_tester.test_strategies(strategies, 10000);
|
||||
println!("Strategy comparison: {:?}", results);
|
||||
```
|
||||
|
||||
## Performance
|
||||
|
||||
### Simulation Speed
|
||||
- **Simple Hand**: ~1ms per hand simulation
|
||||
- **Complex Analysis**: ~10ms per hand with detailed analysis
|
||||
- **Monte Carlo**: ~100ms per 1000 scenarios
|
||||
- **Tournament**: ~1s per 100-hand tournament
|
||||
|
||||
### Memory Usage
|
||||
- **Base Simulation**: ~1MB per active simulation
|
||||
- **Hand History**: ~10KB per 1000 hands stored
|
||||
- **Analysis Data**: ~50MB per comprehensive analysis
|
||||
|
||||
## Configuration
|
||||
|
||||
### Simulation Parameters
|
||||
|
||||
```toml
|
||||
[simulation]
|
||||
num_players = 6
|
||||
starting_stack = 1000
|
||||
num_hands = 10000
|
||||
save_hand_history = true
|
||||
|
||||
[blinds]
|
||||
small_blind = 10.0
|
||||
big_blind = 20.0
|
||||
ante = 0.0
|
||||
|
||||
[ranges]
|
||||
player1 = "AA,KK,QQ,AK"
|
||||
player2 = "22+,A2+,K2+,Q2+,J2+"
|
||||
player3 = "random"
|
||||
|
||||
[analysis]
|
||||
detailed_equity = true
|
||||
save_distributions = true
|
||||
confidence_interval = 0.95
|
||||
```
|
||||
|
||||
### Custom Scenarios
|
||||
|
||||
```rust
|
||||
// Create custom test scenarios
|
||||
let scenario = SimulationScenario {
|
||||
name: "Premium vs Fish".to_string(),
|
||||
players: vec![
|
||||
PlayerConfig { name: "Pro", range: "AA,KK,QQ,AK,AQ".to_string(), stack: 2000 },
|
||||
PlayerConfig { name: "Fish", range: "22+,A2+,K2+".to_string(), stack: 500 },
|
||||
],
|
||||
board_texture: BoardTexture::Dry, // Flop texture for analysis
|
||||
num_simulations: 10000,
|
||||
};
|
||||
```
|
||||
|
||||
## Output and Reporting
|
||||
|
||||
### Results Format
|
||||
|
||||
```rust
|
||||
pub struct SimulationResults {
|
||||
pub total_hands: usize,
|
||||
pub player_results: Vec<PlayerResult>,
|
||||
pub hand_distribution: HashMap<String, usize>,
|
||||
pub equity_distribution: Vec<f64>,
|
||||
pub confidence_intervals: Vec<(f64, f64)>,
|
||||
}
|
||||
```
|
||||
|
||||
### Report Generation
|
||||
|
||||
```rust
|
||||
// Generate comprehensive reports
|
||||
let reporter = SimulationReporter::new();
|
||||
reporter.add_results(results);
|
||||
reporter.generate_html_report("simulation_report.html");
|
||||
reporter.generate_csv_summary("summary.csv");
|
||||
```
|
||||
|
||||
## Integration
|
||||
|
||||
The simulator integrates with:
|
||||
- **Core API**: Uses hand evaluation and card management
|
||||
- **Bot Framework**: Tests bot implementations in controlled environments
|
||||
- **Analysis Tools**: Provides data for strategy analysis and improvement
|
||||
- **Log System**: Integrates with logging and monitoring tools
|
||||
|
||||
## Development
|
||||
|
||||
### Extending the Simulator
|
||||
|
||||
#### Adding New Game Types
|
||||
```rust
|
||||
// Implement new poker variant
|
||||
pub struct OmahaSimulation {
|
||||
// Omaha-specific logic
|
||||
}
|
||||
|
||||
impl PokerSimulation for OmahaSimulation {
|
||||
fn simulate_hand(&mut self) -> HandResult {
|
||||
// Omaha simulation logic
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Custom Analysis Modules
|
||||
```rust
|
||||
// Add custom analysis
|
||||
pub struct BluffAnalyzer {
|
||||
// Bluff detection logic
|
||||
}
|
||||
|
||||
impl HandAnalyzer for BluffAnalyzer {
|
||||
fn analyze(&self, hand: &Hand) -> AnalysisResult {
|
||||
// Custom analysis logic
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Use Cases
|
||||
|
||||
### Bot Development
|
||||
- Test bot strategies against known ranges
|
||||
- Identify leaks in bot decision-making
|
||||
- Optimize bot parameters and configurations
|
||||
|
||||
### Strategy Research
|
||||
- Analyze range vs range scenarios
|
||||
- Study board texture effects
|
||||
- Research optimal bet sizing
|
||||
|
||||
### Game Theory
|
||||
- Equilibrium analysis for different stack sizes
|
||||
- Nash equilibrium calculations
|
||||
- Exploitability analysis
|
||||
|
||||
### Performance Testing
|
||||
- Load testing for poker platforms
|
||||
- Scalability analysis
|
||||
- Performance benchmarking
|
||||
|
|
@ -1 +1 @@
|
|||
{"rustc_fingerprint":7356878809457778000,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.81.0 (eeb90cda1 2024-09-04)\nbinary: rustc\ncommit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c\ncommit-date: 2024-09-04\nhost: x86_64-pc-windows-msvc\nrelease: 1.81.0\nLLVM version: 18.1.7\n","stderr":""},"16495917692426387086":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\jan\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}}
|
||||
{"rustc_fingerprint":9168241167641241758,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\jan\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.81.0 (eeb90cda1 2024-09-04)\nbinary: rustc\ncommit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c\ncommit-date: 2024-09-04\nhost: x86_64-pc-windows-msvc\nrelease: 1.81.0\nLLVM version: 18.1.7\n","stderr":""},"16495917692426387086":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""}},"successes":{}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue