working mvp, missing corners/splits/triples

This commit is contained in:
Michael Pilosov 2022-11-11 13:18:42 -07:00
commit 17c705dac5

93
app.py Normal file
View File

@ -0,0 +1,93 @@
from typing import List, Dict
from functools import reduce
FEASIBLE_MOVES = sorted({
*[f"street-{i}" for i in range(1,14)],
*[f"col-{i}" for i in range(1,4)],
*["1-12", "13-24", "25-36", "first-half", "last-half", "even", "odd", "red", "black"],
})
ALIASES = {"reds", "blacks", "evens", "odds"}
def expectation(bet):
odds = 0
pmnt = 0
return odds * pmnt
# 38 numbers, 6 street bets, 2 half-bets,
# payout grid based on bets placed.
# a street bet is the same as splitting the bet across all the numbers in the group.
# will use a function to distribute / interpret the bets, but it seems like we only need to track the numbers on the wheel.
def init_bet() -> Dict[int, float]:
D = {i: 0 for i in range(-1, 37)}
return D
def place_bet(bet: Dict[str, float], on: int, amount: float):
bet = bet.copy()
bet[on] += amount
return bet
def interpret_bet(on="red", amount=0, bet=None):
assert (on in FEASIBLE_MOVES) or (on in ALIASES), f"Bet not understood. Choose from feasible moves:\n {FEASIBLE_MOVES}"
if bet is None:
bet = init_bet()
else:
bet = bet.copy()
REDS = {1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36}
BLACKS = set(range(37)) - REDS
NUMS = {}
on = on.strip().replace(" ", "-")
div = 18
if on in ("red", "reds"):
NUMS = REDS
if on in ("black", "blacks"):
NUMS = BLACKS
if on in ("odd", "odds"):
NUMS = {i for i in range(37) if i % 2 == 0}
if on in ("even", "evens"):
NUMS = {i for i in range(37) if i % 2}
if on in ("first-18", "first-half"):
NUMS = set(range(1, 19))
if on in ("last-18", "last-half"):
NUMS = set(range(19, 37))
if on in ("1-12", "13-24", "25-36"):
low, high = on.split("-")
NUMS = set(range(low, high+1))
div = 12
if not NUMS:
other_bet = on.split("-")
if other_bet[0] == "street":
street = int(other_bet[1]) - 1
assert street in list(range(13))
NUMS = {i for i in range(street+1, street+4)}
div = 3
elif other_bet[0] == "col":
col = int(other_bet[1]) - 1
assert col in list(range(0,3))
NUMS = {i for i in range(1, 37) if (i-1) % 3 == col}
div = 12
else:
raise ValueError("unsupported bet")
bet = reduce(lambda bet, num: place_bet(bet, num, amount / div), NUMS, bet)
return bet
bet = init_bet()
bet = place_bet(bet, 21, 20)
print(bet[21])
#bet = interpret_bet("red", 36, bet)
#bet = interpret_bet("25-36", 1, bet)
bet = interpret_bet("street-1", 3, bet)
bet = interpret_bet("street-10", 3, bet)
bet = interpret_bet("col-1", 12, bet)
print(bet[21])
print(bet)