From c32569f3c1dac773695f18c1f911643579c0b7db Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Sat, 26 Nov 2022 22:55:37 -0700 Subject: [PATCH] bump version, reorder functions and simplify code. --- pyroulette/roulette.py | 87 +++++++++++++++--------------------------- setup.py | 2 +- 2 files changed, 32 insertions(+), 57 deletions(-) diff --git a/pyroulette/roulette.py b/pyroulette/roulette.py index 4912d5e..a28ecd7 100644 --- a/pyroulette/roulette.py +++ b/pyroulette/roulette.py @@ -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 diff --git a/setup.py b/setup.py index de42992..c07690f 100644 --- a/setup.py +++ b/setup.py @@ -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",