Skip to content

Commit

Permalink
docs: improve arena documentation
Browse files Browse the repository at this point in the history
Summary:
- Add some rustdocs

Test Plan:
`nix flake check`
  • Loading branch information
elliottneilclark committed Feb 19, 2024
1 parent 204c00c commit c8ebd0f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/arena/agent/calling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use crate::arena::{action::AgentAction, game_state::GameState};

use super::Agent;

/// A simple agent that always calls. This can
/// stand in for a player who is a calling
/// station for the rest of a hand.
#[derive(Debug, Clone, Copy)]
pub struct CallingAgent {}

Expand All @@ -11,6 +14,12 @@ impl Agent for CallingAgent {
}
}

impl Default for CallingAgent {
fn default() -> Self {
CallingAgent {}
}
}

#[cfg(test)]
mod tests {
use rand::thread_rng;
Expand Down
2 changes: 2 additions & 0 deletions src/arena/historian/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::arena::action::Action;

use super::Historian;

/// VecHistorian is a historian that will
/// append each action to a vector.
pub struct VecHistorian {
actions: Rc<RefCell<Vec<Action>>>,
}
Expand Down
72 changes: 70 additions & 2 deletions src/arena/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
//! This is the arena module for simulation via agents.
//!
//! # Single Simulation
//!
//! The tools allow explicit control over the
//! simulation all the way down to the rng.
//!
//! ## Single Simulation Example
//!
//! ```
//! use rand::{rngs::StdRng, SeedableRng};
//! use rs_poker::arena::agent::CallingAgent;
//! use rs_poker::arena::agent::RandomAgent;
//! use rs_poker::arena::game_state::GameState;
//! use rs_poker::arena::RngHoldemSimulationBuilder;
//!
//! let stacks = vec![100.0, 100.0];
//! let agents: Vec<Box<dyn rs_poker::arena::Agent>> = vec![
//! Box::<CallingAgent>::default(),
//! Box::<RandomAgent>::default(),
//! ];
//! let rng = StdRng::seed_from_u64(420);
//!
//! let game_state = GameState::new(stacks, 10.0, 5.0, 0);
//! let mut sim = RngHoldemSimulationBuilder::default()
//! .game_state(game_state)
//! .rng(rng)
//! .agents(agents)
//! .build()
//! .unwrap();
//!
//! let result = sim.run();
//! ```
//!
//! # Competition Example
//!
//! It's also possible to run a competition where the
//! same agents compete in multiple simulations
//! with tabulated results
//!
//! ```
//! use rs_poker::arena::agent::CallingAgent;
//! use rs_poker::arena::agent::FoldingAgent;
//! use rs_poker::arena::agent::RandomAgent;
//! use rs_poker::arena::competition::CloneAgent;
//! use rs_poker::arena::competition::CloningAgentsGenerator;
//! use rs_poker::arena::competition::EmptyHistorianGenerator;
//! use rs_poker::arena::competition::HoldemCompetition;
//! use rs_poker::arena::competition::RandomGameStateGenerator;
//! use rs_poker::arena::competition::StandardSimulationGenerator;
//!
//! // We are not limited to just heads up. We can have up to full ring of 9 agents.
//! let agents: Vec<Box<dyn CloneAgent>> = vec![
//! Box::<CallingAgent>::default(),
//! Box::<RandomAgent>::default(),
//! Box::<FoldingAgent>::default(),
//! ];
//!
//! let agent_gen = CloningAgentsGenerator::new(agents);
//! let game_state_gen = RandomGameStateGenerator::new(3, 100.0, 500.0, 10.0, 5.0);
//! let sim_gen =
//! StandardSimulationGenerator::new(agent_gen, game_state_gen, EmptyHistorianGenerator);
//!
//! let mut competition = HoldemCompetition::new(sim_gen);
//!
//! let _first_results = competition.run(100).unwrap();
//! let recent_results = competition.run(100).unwrap();
//!
//! // The holdem competition tabulates the results accross multiple runs.
//! println!("{:?}", recent_results);
//! ```
/// Public module containing types for actions that agents can take in the
/// arena.
pub mod action;
pub mod agent;
pub mod competition;
Expand Down
13 changes: 9 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@
//! expected values are. The arena is configurable for number of players from
//! heads up all the way to full ring.
//!
//! The arena has three main parts:
//! The arena has several parts:
//! * `GameState` this holds the current state of all the chips, bets, player
//! all in status, and if players are active in a hand or round.
//! * `Agent` is the trait needed to implement different automatic players in
//! the poker.
//! * `Historian` is the trait implemented to recieve actions as they happen to
//! * to the gamestate.
//! * `HoldemSimulation` this is the main wrapper struct that handles calling
//! the agents and force folding the agents for any invalid actions.
//! * `HoldemSimulationBuilder` that is used to construcst single simulations.
//! `GameState` and `Agents` are required the rest are optional
//! * `HoldemCompetition` that keeps track of all simulation based stats from
//! simluations genreated via `HoldemSimulationGenerator`.
//! * Each `HoldemSimulationGenerator` is built of `AgentsGenerator`,
//! `HistorianGenerator`, and `GameStateGenerator`
#![deny(clippy::all)]
extern crate rand;

Expand All @@ -149,8 +157,5 @@ pub mod holdem;
/// equity in the total tournament.
pub mod simulated_icm;

/// Simulate poker games via agents that
/// play. Then determine who wins the most over
/// time
#[cfg(feature = "arena")]
pub mod arena;

0 comments on commit c8ebd0f

Please sign in to comment.