Crate cfr

Source
Expand description

Counterfactual Regret (CFR) is a library for finding an approximate nash equilibrium in two-player zero-sum games of incomplete information with perfect recall, such as poker etc., using discounted1 monte carlo2 counterfactual regret minimization3.

§Usage

To use the command line tool, see documentation on github, or use cfr --help.

To use this as a rust library, define the IntoGameNode trait for the representation of your extensive form game. See the trait for details and contracts of implementation. The use of IntoIterator allows this conversion to be zero-copy for expensive types, e.g. long history information sets. Once this trait is defined, create an efficient representation of the Game with from_root. Compute an approximate equilibrium with Game::solve. You can then get equilibrium utilities and regret from Strategies::get_info.

§Examples

Once the conversion trait, IntoGameNode, is defined for your game, you solve for equilibria like:

impl IntoGameNode for ExData {
    // ...
}
let data: ExData = // ...
let game = Game::from_root(data).unwrap();
let (strats, reg_bounds) = game.solve(
    SolveMethod::External,
    100,  // number of iterations
    0.0,  // early termination regret
    1,    // number of threads
    None, // advanced options
).unwrap();
// get named versions, i.e. exportable version
let named = strats.as_named();
// compute regret and other values
let strat_info = strats.get_info();
let regret = strat_info.regret();

Structs§

Game
A compact game representation
NamedStrategyActionIter
An iterator over named actions and assiciated probabilities
NamedStrategyIter
An iterator over named information sets of a strategy.
RegretBound
Regret bound produced by solving a game
RegretParams
Advanced parameters for regret calculation
Strategies
A compact strategy for both players
StrategiesInfo
Information about the regret and utility of a specific strategy profile

Enums§

GameError
Errors that result from game definition errors
GameNode
An intemediary representation of a node in a game tree
PlayerNum
An enum indicating a player
SolveError
Errors that result from problems solving
SolveMethod
The method to use for finding approximate equilibria
StratError
Errors that result from incompatible strategy representation

Traits§

IntoGameNode
A trait that defines how to convert game-tree-like data into a Game