native-solver
A heads-up postflop No-Limit Hold'em solver in Rust. It includes:
- a table-driven 5- and 7-card hand evaluator,
- weighted preflop ranges that expand into concrete two-card combos,
- betting-tree construction from the flop, turn, or river with configurable bet sizes and raise caps,
- a combo-vectorized CFR trainer with CFR, CFR+, and Discounted CFR, simultaneous or alternating updates, optional suit-isomorphism reduction and card abstraction,
- per-node EV and river equity under the average strategy, and an exact exploitability (best-response) metric.
Installation
Or add native-solver = "0.1" under [dependencies] in Cargo.toml.
Example
Solve a river spot, measure how far the result is from equilibrium, and print the first player's strategy for each combo:
use ;
The output starts like this:
exploitability: 0.060 chips
JcTc check 100% bet 50 0% bet 100 0%
JdTd check 100% bet 50 0% bet 100 0%
JsTs check 0% bet 50 0% bet 100 100%
...
Training more iterations lowers exploitability; the iteration count by itself
says nothing about convergence. Check exploitability() instead.
Training runs in parallel on Rayon's global thread pool. The thread count does not change the results; see docs/algorithms.md.
Errors
build_tree returns a TreeError for an illegal board, a non-positive pot,
a negative stack, or a bet size that is not a positive finite number.
Trainer::new returns a TrainerError for inputs it cannot solve, for
example when the tree does not continue from the initial board, or when a
range is empty, contains invalid, repeated, or board-blocked combos, or
cannot be dealt against the other range. Pass the board as dead cards to
Range::combos to remove blocked combos.
Conventions
Raw counterfactual values are not EVs, and exploitability is reported in chips. See docs/conventions.md for units, value normalization, and the requirements of suit-isomorphism reduction, and docs/algorithms.md for the update rules.
Limitations
- Heads-up and postflop only: no preflop tree, multiway pots, or side pots.
- No rake.
- Bet sizes are fractions of the pot. An all-in is not added automatically, so include a large enough fraction if you want one.
- Equity is reported only on a complete five-card board.
- Memory grows with tree size × combo count. Use
build_tree_boundedfor untrusted input.
Benchmarks
examples/ holds benchmark programs that use only the public API. For
example, cargo run --release --example solver_performance -- --help lists
the workloads of the end-to-end solver benchmark.
Stability
The API may change in any 0.x minor release. Breaking changes are listed
in CHANGELOG.md.
Minimum supported Rust version
Rust 1.80 for the library. The tests and benchmarks need Rust 1.85 or newer, because a dev-dependency (Criterion) requires it.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.