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
14 changes: 7 additions & 7 deletions treys/card.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Sequence
from typing import Sequence, List, Dict

class Card:
"""
Expand Down Expand Up @@ -31,11 +31,11 @@ class Card:
STR_RANKS: str = '23456789TJQKA'
STR_SUITS: str = 'shdc'
INT_RANKS: range = range(13)
PRIMES: list[int] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
PRIMES: List[int] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]

# conversion from string => int
CHAR_RANK_TO_INT_RANK: dict[str, int] = dict(zip(list(STR_RANKS), INT_RANKS))
CHAR_SUIT_TO_INT_SUIT: dict[str, int] = {
CHAR_RANK_TO_INT_RANK: Dict[str, int] = dict(zip(list(STR_RANKS), INT_RANKS))
CHAR_SUIT_TO_INT_SUIT: Dict[str, int] = {
's': 1, # spades
'h': 2, # hearts
'd': 4, # diamonds
Expand All @@ -48,14 +48,14 @@ class Card:
INT_SUIT_TO_CHAR_SUIT: str = 'xshxdxxxc'

# for pretty printing
PRETTY_SUITS: dict[int, str] = {
PRETTY_SUITS: Dict[int, str] = {
1: chr(9824), # spades
2: chr(9829), # hearts
4: chr(9830), # diamonds
8: chr(9827) # clubs
}

SUIT_COLORS: dict[int, str] = {
SUIT_COLORS: Dict[int, str] = {
2: "red",
4: "blue",
8: "green"
Expand Down Expand Up @@ -104,7 +104,7 @@ def get_prime(card_int: int) -> int:
return card_int & 0x3F

@staticmethod
def hand_to_binary(card_strs: Sequence[str]) -> list[int]:
def hand_to_binary(card_strs: Sequence[str]) -> List[int]:
"""
Expects a list of cards as strings and returns a list
of integers of same length corresponding to those strings.
Expand Down
7 changes: 4 additions & 3 deletions treys/deck.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from random import Random
from typing import List

from .card import Card

Expand All @@ -9,7 +10,7 @@ class Deck:
deck with the list of unique card integers. Each object instantiated simply
makes a copy of this object and shuffles it.
"""
_FULL_DECK: list[int] = []
_FULL_DECK: List[int] = []

def __init__(self, seed: int = None) -> None:
self._random = Random(seed)
Expand All @@ -20,7 +21,7 @@ def shuffle(self) -> None:
self.cards = Deck.GetFullDeck()
self._random.shuffle(self.cards)

def draw(self, n: int = 1) -> list[int]:
def draw(self, n: int = 1) -> List[int]:
cards = []
for _ in range(n):
cards.append(self.cards.pop())
Expand All @@ -30,7 +31,7 @@ def __str__(self) -> str:
return Card.ints_to_pretty_str(self.cards)

@staticmethod
def GetFullDeck() -> list[int]:
def GetFullDeck() -> List[int]:
if Deck._FULL_DECK:
return list(Deck._FULL_DECK)

Expand Down
8 changes: 4 additions & 4 deletions treys/evaluator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import itertools
from typing import Sequence
from typing import Sequence, List

from .card import Card
from .lookup import LookupTable
Expand Down Expand Up @@ -29,7 +29,7 @@ def __init__(self) -> None:
7: self._seven
}

def evaluate(self, hand: list[int], board: list[int]) -> int:
def evaluate(self, hand: List[int], board: List[int]) -> int:
"""
This is the function that the user calls to get a hand rank.

Expand Down Expand Up @@ -129,7 +129,7 @@ def get_five_card_rank_percentage(self, hand_rank: int) -> float:
"""
return float(hand_rank) / float(LookupTable.MAX_HIGH_CARD)

def hand_summary(self, board: list[int], hands: list[list[int]]) -> None:
def hand_summary(self, board: List[int], hands: List[List[int]]) -> None:
"""
Gives a sumamry of the hand with ranks as time proceeds.

Expand Down Expand Up @@ -189,7 +189,7 @@ class PLOEvaluator(Evaluator):

HAND_LENGTH = 4

def evaluate(self, hand: list[int], board: list[int]) -> int:
def evaluate(self, hand: List[int], board: List[int]) -> int:
minimum = LookupTable.MAX_HIGH_CARD

for hand_combo in itertools.combinations(hand, 2):
Expand Down
14 changes: 7 additions & 7 deletions treys/lookup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Iterator
import itertools
from typing import Sequence
from typing import Sequence, Dict

from .card import Card

Expand Down Expand Up @@ -39,7 +39,7 @@ class LookupTable:
MAX_PAIR: int = 6185
MAX_HIGH_CARD: int = 7462

MAX_TO_RANK_CLASS: dict[int, int] = {
MAX_TO_RANK_CLASS: Dict[int, int] = {
MAX_ROYAL_FLUSH: 0,
MAX_STRAIGHT_FLUSH: 1,
MAX_FOUR_OF_A_KIND: 2,
Expand All @@ -52,7 +52,7 @@ class LookupTable:
MAX_HIGH_CARD: 9
}

RANK_CLASS_TO_STRING: dict[int, str] = {
RANK_CLASS_TO_STRING: Dict[int, str] = {
0: "Royal Flush",
1: "Straight Flush",
2: "Four of a Kind",
Expand All @@ -70,8 +70,8 @@ def __init__(self) -> None:
Calculates lookup tables
"""
# create dictionaries
self.flush_lookup: dict[int, int] = {}
self.unsuited_lookup: dict[int, int] = {}
self.flush_lookup: Dict[int, int] = {}
self.unsuited_lookup: Dict[int, int] = {}

# create the lookup table in piecewise fashion
# this will call straights and high cards method,
Expand Down Expand Up @@ -255,15 +255,15 @@ def multiples(self) -> None:
self.unsuited_lookup[product] = rank
rank += 1

def write_table_to_disk(self, table: dict[int, int], filepath: str) -> None:
def write_table_to_disk(self, table: Dict[int, int], filepath: str) -> None:
"""
Writes lookup table to disk
"""
with open(filepath, 'w') as f:
for prime_prod, rank in table.items():
f.write(str(prime_prod) + "," + str(rank) + '\n')

def get_lexographically_next_bit_sequence(self, bits: int) -> Iterator[int]:
def get_lexographically_next_bit_sequence(self, bits: int) -> Sequence[int]:
"""
Bit hack from here:
http://www-graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation
Expand Down