bump version, reorder functions and simplify code.

This commit is contained in:
Michael Pilosov 2022-11-26 22:55:37 -07:00
parent 6c16d2986b
commit c32569f3c1
2 changed files with 32 additions and 57 deletions

View File

@ -7,6 +7,35 @@ from random import choice, randint
from statistics import mean, stdev
from typing import Dict, List, Optional
SINGLE_BETS = {str(i) for i in range(-1, 37)}
FEASIBLE_MOVES = sorted(
{
*[f"street-{i}" for i in range(1, 14)],
*[f"col-{i}" for i in range(1, 4)],
*[f"corner-{i}-{i+1}-{i+3}-{i+4}" for i in range(1, 33) if (i - 1) % 3 < 2],
*["1-12", "13-24", "25-36", "1-18", "19-36", "even", "odd", "red", "black"],
*["triple-0", "triple-00"],
*SINGLE_BETS,
}
)
ALIASES = {
"reds",
"blacks",
"evens",
"odds",
"first-half",
"last-half",
"second-half",
"first-18",
"last-18",
"second-18",
}
CHIP_VALUES = {0.25, 0.5, 1, 5, 10, 25, 50, 100}
def init_spread() -> Dict[int, float]:
"""
@ -21,26 +50,6 @@ def init_spread() -> Dict[int, float]:
return D
def combine_bets(bet_1: Bet, bet_2: Bet) -> Bet:
"""
Combines two bets into a single bet.
Parameters
----------
bet_1 : Bet
The first bet to combine.
bet_2 : Bet
The second bet to combine.
Returns
-------
Bet
The combined bet.
"""
# TODO: can remove the default 0.
return Bet({k: bet_1[k] + bet_2[k] for k in set(bet_1) | set(bet_2)})
@dataclass
class Bet:
"""A class for representing a bet."""
@ -69,7 +78,7 @@ class Bet:
def __add__(self, other: Bet) -> Bet:
"""Combine two bets."""
return combine_bets(self, other)
return Bet({k: self[k] + other[k] for k in set(self) | set(other)})
def __setitem__(self, __name: int, __value: float) -> None:
"""Set the value of a placement."""
@ -90,36 +99,6 @@ class Bet:
return self.spread.get(__name, 0)
SINGLE_BETS = {str(i) for i in range(-1, 37)}
FEASIBLE_MOVES = sorted(
{
*[f"street-{i}" for i in range(1, 14)],
*[f"col-{i}" for i in range(1, 4)],
*[f"corner-{i}-{i+1}-{i+3}-{i+4}" for i in range(1, 33) if (i - 1) % 3 < 2],
*["1-12", "13-24", "25-36", "1-18", "19-36", "even", "odd", "red", "black"],
*["triple-0", "triple-00"],
*SINGLE_BETS,
}
)
ALIASES = {
"reds",
"blacks",
"evens",
"odds",
"first-half",
"last-half",
"second-half",
"first-18",
"last-18",
"second-18",
}
CHIP_VALUES = {0.25, 0.5, 1, 5, 10, 25, 50, 100}
@dataclass
class Placement:
"""
@ -269,11 +248,7 @@ class Strategy:
Bet
A dictionary representing the bet.
"""
return reduce(
lambda bet, placement: combine_bets(bet, placement.bet()),
placements,
Bet(),
)
return sum([p.bet() for p in placements], Bet())
@dataclass

View File

@ -10,7 +10,7 @@ with open(BASEDIR.joinpath("README.md"), "r") as fp:
setup(
name="pyroulette",
version="0.0.1rc5",
version="0.0.1rc6",
description="A package for exploring roulette strategies.",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",