Skip to main content

Crate pkstate

Crate pkstate 

Source
Expand description

§pkstate

A library for representing, serializing, and deserializing the state of a poker hand.

pkstate models everything needed to describe a hand in progress or a complete hand history: the game type, forced bets, the players at the table, the community board cards, and the full sequence of actions across every street. All types implement serde::Serialize and serde::Deserialize, with BasicPile card collections serialized as human-readable Unicode card strings (e.g. "A♠ K♥").

§Modules

§Example

use pkstate::{PKState, act::{Action, Round}, game::{ForcedBets, GameType}, seat::Seat};
use cardpack::prelude::*;

let players = vec![
    Seat { id: None, name: "Alice".to_string(), stack: 1_000 },
    Seat { id: None, name: "Bob".to_string(),   stack: 1_000 },
];

let preflop = Round(vec![
    Action::P0Dealt(basic!("A♠ K♠")),
    Action::P1Dealt(basic!("7♦ 2♣")),
    Action::P0CBR(100),
    Action::P1Fold,
    Action::P0Wins(100),
]);

let state = PKState {
    id: Some("example-hand".to_string()),
    datetime: None,
    game: GameType::NoLimitHoldem,
    button: 0,
    forced_bets: ForcedBets::new(50, 100),
    board: None,
    players,
    rounds: vec![preflop],
};

let yaml = serde_yaml_bw::to_string(&state).unwrap();
let restored: PKState = serde_yaml_bw::from_str(&yaml).unwrap();
assert_eq!(state, restored);

Modules§

act
Actions and betting rounds.
game
Game type and forced bet configuration.
seat
Player seat representation.
util

Structs§

PKState
The complete state of a poker hand.
PKStates