1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//! 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::{SeedableRng, rngs::StdRng};
//! use rs_poker::arena::HoldemSimulationBuilder;
//! use rs_poker::arena::GameStateBuilder;
//! use rs_poker::arena::agent::CallingAgent;
//! use rs_poker::arena::agent::RandomAgent;
//!
//! let rt = tokio::runtime::Runtime::new().unwrap();
//! rt.block_on(async {
//! let agents: Vec<Box<dyn rs_poker::arena::Agent>> = vec![
//! Box::<CallingAgent>::default(),
//! Box::<RandomAgent>::default(),
//! ];
//!
//! let game_state = GameStateBuilder::new()
//! .num_players_with_stack(2, 100.0)
//! .blinds(10.0, 5.0)
//! .build()
//! .unwrap();
//! let mut sim = HoldemSimulationBuilder::default()
//! .game_state(game_state)
//! .agents(agents)
//! .build_with_rng(StdRng::seed_from_u64(420))
//! .unwrap();
//!
//! sim.run().await;
//! });
//! ```
//!
//! # Competition Examples
//!
//! ## `HoldemCompetition` Example
//!
//! It's also possible to run a competition where the
//! same agents compete in multiple simulations
//! with tabulated results
//!
//! ```
//! use rs_poker::arena::AgentGenerator;
//! use rs_poker::arena::agent::CallingAgentGenerator;
//! use rs_poker::arena::agent::FoldingAgentGenerator;
//! use rs_poker::arena::agent::RandomAgentGenerator;
//! use rs_poker::arena::competition::HoldemCompetition;
//! use rs_poker::arena::competition::StandardSimulationIterator;
//! use rs_poker::arena::game_state::RandomGameStateGenerator;
//!
//! // We are not limited to just heads up. We can have up to full ring of 9 agents.
//! let agent_gens: Vec<Box<dyn AgentGenerator>> = vec![
//! Box::<CallingAgentGenerator>::default(),
//! Box::<FoldingAgentGenerator>::default(),
//! Box::<RandomAgentGenerator>::default(),
//! ];
//!
//! let game_state_gen = RandomGameStateGenerator::new(3, 100.0, 500.0, 10.0, 5.0, 0.0);
//! let sim_gen = StandardSimulationIterator::new(agent_gens, vec![], game_state_gen);
//!
//! let mut competition = HoldemCompetition::new(sim_gen);
//!
//! let rt = tokio::runtime::Runtime::new().unwrap();
//! rt.block_on(async {
//! let _first_results = competition.run(100).await.unwrap();
//! let recent_results = competition.run(100).await.unwrap();
//!
//! // The holdem competition tabulates the results accross multiple runs.
//! println!("{:?}", recent_results);
//! });
//! ```
//!
//! ## `SingleTableTournament` Example
//!
//! It's also possible to run a single table tournament where the
//! game state continues on until one player has all the money.
//!
//! ```
//! use rs_poker::arena::AgentGenerator;
//! use rs_poker::arena::GameStateBuilder;
//! use rs_poker::arena::agent::RandomAgentGenerator;
//! use rs_poker::arena::competition::SingleTableTournamentBuilder;
//!
//! // We are not limited to just heads up. We can have up to full ring of 9 agents.
//! let agent_gens: Vec<Box<dyn AgentGenerator>> = vec![
//! Box::<RandomAgentGenerator>::default(),
//! Box::<RandomAgentGenerator>::default(),
//! Box::<RandomAgentGenerator>::default(),
//! Box::<RandomAgentGenerator>::default(),
//! ];
//!
//! // This is the starting game state.
//! let game_state = GameStateBuilder::new()
//! .num_players_with_stack(4, 100.0)
//! .blinds(10.0, 5.0)
//! .ante(1.0)
//! .build()
//! .unwrap();
//!
//! let tournament = SingleTableTournamentBuilder::default()
//! .agent_generators(agent_gens)
//! .starting_game_state(game_state)
//! .build(rand::rng())
//! .unwrap();
//!
//! let rt = tokio::runtime::Runtime::new().unwrap();
//! let results = rt.block_on(tournament.run()).unwrap();
//! ```
//!
//! ## Counter Factual Regret Minimization (CFR) Example
//!
//! rs-poker has an implementation of CFR that can be used to implement agents
//! that decide their actions based on the regret minimization algorithm. For
//! that you can use the `CFRAgent` along with the `CFRHistorian` and `CFRState`
//! structs.
//!
//! The strategy is implemented by the `ActionGenerator` trait, which is used to
//! generate potential actions for a given game state. The
//! `BasicCFRActionGenerator` is a simple implementation that generates fold,
//! call, and All-In actions.
//!
//! Tree recursion is controlled by `MaxWidth` (a `Budget` impl):
//! `MaxWidth.recursive_widths` gives the per-depth wave width, and depths
//! past the end of that vec use the cheap fast-forward reward path. The
//! number of waves at each depth is governed by the rest of the `Budget`.
//!
//! The Agent then chooses the action based upon the regret minimization.
//!
//! ```
//! use rs_poker::arena::cfr::CFRAgent;
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use seeded_rng;
pub use HoldemSimulationBuilder;
pub use HoldemSimulation;