rs_poker 5.0.0

A library to help with any Rust code dealing with poker. This includes card values, suits, hands, hand ranks, 5 card hand strength calculation, 7 card hand strength calulcation, and monte carlo game simulation helpers.
Documentation
mod basic;
mod configurable;
mod preflop_chart;
mod simple;

use std::sync::Arc;

use smallvec::SmallVec;

use crate::arena::{GameState, action::AgentAction};

use super::{CFRState, TraversalState};

/// Inline, sliceable list of generated actions. A node's action set is small
/// (a handful: fold/call + a few bet sizes + all-in), so this stays on the
/// stack instead of heap-allocating a `Vec` per node visit. The trait only
/// requires the result to be sliceable, so generators (and tests) are free to
/// produce any `Into<ActionVec>` source; the engine consumes it as `&[_]`.
pub type ActionVec = SmallVec<[AgentAction; 8]>;

pub use basic::BasicCFRActionGenerator;
pub use configurable::{
    ConfigurableActionConfig, ConfigurableActionConfigError, ConfigurableActionGenerator,
    RoundActionConfig,
};
pub use preflop_chart::{
    PositionCharts, PreflopChartActionConfig, PreflopChartActionGenerator, PreflopChartConfig,
    PreflopChartConfigError,
};
pub use simple::SimpleActionGenerator;

/// Trait for generating possible actions in CFR.
///
/// ActionGenerators are responsible for:
/// 1. Generating all possible actions for a given game state
/// 2. Holding references to CFR state and traversal state
///
/// Action-to-index mapping and action selection are now handled by
/// `ActionIndexMapper` and `ActionPicker` respectively, which use
/// a fixed 52-action space for consistent tree traversal.
pub trait ActionGenerator {
    /// The configuration type for this action generator.
    /// Use `()` for generators that don't need configuration.
    type Config: Clone + Send + Sync;

    /// Create a new action generator
    ///
    /// Config is passed as `Arc` to allow cheap cloning when constructing
    /// many sub-agents during CFR tree traversal.
    fn new(cfr_state: CFRState, traversal_state: TraversalState, config: Arc<Self::Config>)
    -> Self;

    /// Get a reference to the configuration
    fn config(&self) -> &Self::Config;

    /// Get a reference to the CFR state
    fn cfr_state(&self) -> &CFRState;

    /// Get a reference to the traversal state
    fn traversal_state(&self) -> &TraversalState;

    /// Generate all possible actions for the current game state.
    ///
    /// Returns an [`ActionVec`] (inline, sliceable) of valid actions that can be
    /// taken. The actions will be mapped to indices using `ActionIndexMapper`
    /// for tree traversal.
    fn gen_possible_actions(&self, game_state: &GameState) -> ActionVec;
}