modulepackage
0.0.0-20230208023716-2c859fbaa0a5
Repository: https://github.com/timpalpant/go-cfr.git
Documentation: pkg.go.dev
# README
go-cfr
go-cfr is a package that implements several forms of Counterfactual Regret Minimization in Go. CFR can be used to solve for an approximate Nash Equilibrium in an imperfect information extensive-form game.
This project is a research library used to study different forms of CFR. For a similar alternative in C++/Python/Swift, see OpenSpiel.
Usage
To use CFR, you must implement the extensive-form game tree for your game,
by implementing the GameTreeNode
interface.
An implementation of Kuhn Poker is included as an example.
package main
import (
"fmt"
"github.com/timpalpant/go-cfr"
"github.com/timpalpant/go-cfr/kuhn"
"github.com/timpalpant/go-cfr/tree"
)
func main() {
poker := kuhn.NewGame()
policy := cfr.NewPolicyTable(cfr.DiscountParams{})
vanillaCFR := cfr.New(policy)
nIter := 10000
expectedValue := float32(0.0)
for i := 1; i <= nIter; i++ {
expectedValue += vanillaCFR.Run(poker)
}
expectedValue /= float32(nIter)
fmt.Printf("Expected value is: %v\n", expectedValue)
seen := make(map[string]struct{})
tree.Visit(poker, func(node cfr.GameTreeNode) {
if node.Type() != cfr.PlayerNodeType {
return
}
key := node.InfoSet(node.Player()).Key()
if _, ok := seen[string(key)]; ok {
return
}
actionProbs := policy.GetPolicy(node).GetAverageStrategy()
if actionProbs != nil {
fmt.Printf("[player %d] %6s: check=%.2f bet=%.2f\n",
node.Player(), key, actionProbs[0], actionProbs[1])
}
seen[string(key)] = struct{}{}
})
}
Variants implemented
- Vanilla CFR: https://poker.cs.ualberta.ca/publications/NIPS07-cfr.pdf
- CFR+: https://arxiv.org/abs/1407.5042
- Discounted (including Linear) CFR: https://arxiv.org/abs/1809.04040
- Monte Carlo CFR (MC-CFR):
- Chance Sampling, External Sampling, Outcome Sampling CFR: http://mlanctot.info/files/papers/nips09mccfr.pdf
- Average Strategy CFR: https://papers.nips.cc/paper/4569-efficient-monte-carlo-counterfactual-regret-minimization-in-games-with-many-player-actions.pdf
- Robust Sampling CFR: https://arxiv.org/abs/1901.07621
- Generalized Sampling CFR: https://dl.acm.org/citation.cfm?id=2900920
- Deep CFR: https://arxiv.org/abs/1811.00164
- Single Deep CFR: https://arxiv.org/abs/1901.07621
License
go-cfr is released under the GNU Lesser General Public License, Version 3.0.
# Packages
No description provided by the author
Package kuhn implements an extensive-form game tree for Kuhn Poker, adapted from: https://justinsermeno.com/posts/cfr/.
No description provided by the author
Package rdbstore implements CFR storage components that keep data in a RocksDB database, rather than in memory datastructures.
No description provided by the author
No description provided by the author
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewPolicyTable creates a new PolicyTable with the given DiscountParams.
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
DiscountParams modify how regret is accumulated.
No description provided by the author
No description provided by the author
No description provided by the author
PolicyTable implements traditional (tabular) CFR by storing accumulated regrets and strategy sums for each InfoSet, which is looked up by its Key().
No description provided by the author
# Interfaces
ChanceNode is a node that has a pre-defined probability distribution over its children.
GameTreeNode is the interface for a node in an extensive-form game tree.
InfoSet is the observable game history from the point of view of one player.
NodePolicy maintains the action policy for a single Player node.
PlayerNode is a node in which one of the player's acts.
Sampler selects a subset of child nodes to traverse.
StrategyProfile maintains a collection of regret-matching policies for each player node in the game tree.
Tree node represents a node in a directed rooted tree.
# Type aliases
NodeType is the type of node in an extensive-form game tree.