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
//! Find near-equilibrium strategies for heads-up postflop No-Limit Hold'em
//! spots, and measure how exploitable they are.
//!
//! Give it a board, both players' ranges, the pot, the stacks, and the bet
//! sizes to consider; it trains a strategy with counterfactual regret
//! minimization (CFR, CFR+, or DCFR) and reports per-hand strategies, EVs,
//! and exploitability: how much a perfect opponent could still win against
//! the result. Chip amounts are exact integers, invalid inputs are reported
//! as errors, and an independent reference evaluator can check results on
//! small trees.
//!
//! - [`card`]: [`Card`]s and [`CardSet`]s.
//! - [`eval`]: five- and seven-card hand evaluation.
//! - [`range`]: weighted preflop ranges and their expansion into [`Combo`]s.
//! - [`solver`]: the betting tree ([`GameConfig`], [`build_tree`]) and the
//! combo-vectorized CFR [`Trainer`], with exploitability and node EVs.
//!
//! Only heads-up postflop play is modeled: no preflop, no side pots, no
//! multiway pots. All values are in input chips unless a doc says otherwise.
//!
//! # Example
//!
//! Solve a river spot and check how close the result is to equilibrium:
//!
//! ```
//! use native_solver::{build_tree, Card, CardSet, Chips, GameConfig, Range, Trainer, TrainerOptions};
//!
//! let board = ["Ks", "Th", "7s", "4d", "2s"]
//! .iter()
//! .map(|card| card.parse())
//! .collect::<Result<Vec<Card>, _>>()?;
//! let config = GameConfig::new(board.clone(), Chips::whole(100), Chips::whole(100))
//! .with_bet_sizes([0.5, 1.0]);
//!
//! // Remove combos that share a card with the board.
//! let dead = CardSet::from_cards(&board);
//! let oop = "AA,KK,KQs,QJs,JTs:0.5".parse::<Range>()?.combos(dead);
//! let ip = "AKs,KJs,TT,99,A5s:0.5".parse::<Range>()?.combos(dead);
//!
//! let mut trainer = Trainer::new(build_tree(&config)?, [oop, ip], TrainerOptions::default())?;
//! trainer.train(500);
//!
//! // How much a best response could still gain, in chips.
//! assert!(trainer.exploitability().total < 1.0);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! See [`conventions`] for units and value normalization, and
//! [`algorithms`] for the update rules.
// Compile and run the README example as a doctest.
;
// Kuhn poker: a separate toy CFR with a known closed-form equilibrium, kept
// only to cross-check the update rules in tests.
pub use ;
pub use ;
pub use ;
pub use ;