Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Creating a game tree
To generate a tree for a game, simply specify the rules of the game:

```python
from pokertrees import *
from pokergames import *
from pycfr.pokertrees import *
from pycfr.pokergames import *
players = 2
deck = [Card(14,1),Card(13,2),Card(13,1),Card(12,1)]
rounds = [RoundInfo(holecards=1,boardcards=0,betsize=2,maxbets=[2,2]),RoundInfo(holecards=0,boardcards=1,betsize=4,maxbets=[2,2])]
Expand All @@ -25,7 +25,7 @@ gametree.build()
Or use one of the pre-built games:

```python
from pokergames import *
from pycfr.pokergames import *
gametree = leduc_gametree()
```

Expand All @@ -34,9 +34,9 @@ Evaluating a strategy profile
You can calculate the expected value of a set of strategies for a game:

```python
from pokertrees import *
from pokergames import *
from pokerstrategy import *
from pycfr.pokertrees import *
from pycfr.pokergames import *
from pycfr.pokerstrategy import *
rules = leduc_rules()

# load first player strategy
Expand All @@ -58,9 +58,9 @@ Getting the best response strategy
Given a strategy profile, you can calculate the best response strategy for each agent:

```python
from pokertrees import *
from pokergames import *
from pokerstrategy import *
from pycfr.pokertrees import *
from pycfr.pokergames import *
from pycfr.pokerstrategy import *
rules = leduc_rules()

# load first player strategy
Expand Down Expand Up @@ -95,7 +95,7 @@ Given the rules for a game, you can run the Counterfactual Regret (CFR) Minimiza
hskuhn = half_street_kuhn_rules()

# Create the CFR minimizer
from pokercfr import CounterfactualRegretMinimizer
from pycfr. pokercfr import CounterfactualRegretMinimizer
cfr = CounterfactualRegretMinimizer(hskuhn)

# Run a number of iterations, determining the exploitability of the agents periodically
Expand All @@ -114,7 +114,14 @@ nash_strategies = cfr.profile

Tests
-----
Tests for the game tree code are implemented in the `tests` directory. WARNING: Tests using Leduc poker are slow due to the size of the game.
Tests for the game tree code are implemented in the `pycfr/tests` directory.

Run tests like so:

nosetests -s


Tests are organized as follows:

- test_gametree.py - Tests the game tree functionality against a leduc-like game and verifies some branches are built as expected.

Expand Down
396 changes: 0 additions & 396 deletions pokertrees.py

This file was deleted.

14 changes: 0 additions & 14 deletions popcount.py

This file was deleted.

Empty file added pycfr/__init__.py
Empty file.
30 changes: 16 additions & 14 deletions card.py → pycfr/card.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import re


class Card:
SUIT_TO_STRING = {
1: "s",
2: "h",
3: "d",
4: "c"
}

RANK_TO_STRING = {
2: "2",
3: "3",
Expand All @@ -28,34 +29,35 @@ class Card:
RANK_QUEEN = 12
RANK_KING = 13
RANK_ACE = 14

STRING_TO_SUIT = dict([(v, k) for k, v in SUIT_TO_STRING.iteritems()])
STRING_TO_RANK = dict([(v, k) for k, v in RANK_TO_STRING.iteritems()])

REPR_RE = re.compile(r'\((.*?)\)')

def __init__(self, rank, suit):
"""Create a card. Rank is 2-14, representing 2-A,
while suit is 1-4 representing spades, hearts, diamonds, clubs"""
self.rank = rank
self.suit = suit

def __repr__(self):
return "%s%s" % (self.RANK_TO_STRING[self.rank], self.SUIT_TO_STRING[self.suit])

return "%s%s" % (self.RANK_TO_STRING[self.rank],
self.SUIT_TO_STRING[self.suit])

def __eq__(self, other):
return (isinstance(other, self.__class__) and self.rank == other.rank and self.suit == other.suit)

return isinstance(other, self.__class__) and self.rank == other.rank\
and self.suit == other.suit

def __hash__(self):
return hash((self.rank, self.suit))

@classmethod
def from_repr(cls, repr):
"""Return a card instance from repr.
def from_repr(cls, rpr):
"""Return a card instance from rpr.
This is really dirty--it just matches between the parens.
It's meant for debugging."""
between_parens = re.search(cls.REPR_RE, repr).group(1)
between_parens = re.search(cls.REPR_RE, rpr).group(1)
rank = cls.STRING_TO_RANK[between_parens[0].upper()]
suit = cls.STRING_TO_SUIT[between_parens[1].lower()]
return Card(rank, suit)

Loading