more syntax support

This commit is contained in:
Michael Pilosov 2022-11-25 14:14:53 -07:00
parent 17c705dac5
commit b1b56355f6

78
app.py
View File

@ -4,10 +4,11 @@ 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"],
*[f"corner-{i}-{i+1}-{i+3}-{i+4}" for i in range(1,36) if (i - 1)%3 < 2],
*["1-12", "13-24", "25-36", "1-18", "19-36", "even", "odd", "red", "black"],
})
ALIASES = {"reds", "blacks", "evens", "odds"}
ALIASES = {"reds", "blacks", "evens", "odds", "first-half", "last-half", "second-half", "first-18", "last-18", "second-18"}
def expectation(bet):
odds = 0
@ -35,7 +36,7 @@ def place_bet(bet: Dict[str, float], on: int, amount: float):
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}"
assert (on in FEASIBLE_MOVES) or (on in ALIASES), f"Bet `{on}` not understood. Choose from feasible moves:\n {FEASIBLE_MOVES}"
if bet is None:
bet = init_bet()
else:
@ -50,16 +51,16 @@ def interpret_bet(on="red", amount=0, bet=None):
if on in ("black", "blacks"):
NUMS = BLACKS
if on in ("odd", "odds"):
NUMS = {i for i in range(37) if i % 2 == 0}
NUMS = {i for i in range(1,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 = {i for i in range(1,37) if i % 2}
if on in ("1-18", "first-18", "first-half"):
NUMS = set(range(1, 19))
if on in ("last-18", "last-half"):
if on in ("19-36", "last-18", "last-half", "second-half", "second-18"):
NUMS = set(range(19, 37))
if on in ("1-12", "13-24", "25-36"):
low, high = on.split("-")
NUMS = set(range(low, high+1))
NUMS = set(range(int(low), int(high)+1))
div = 12
if not NUMS:
other_bet = on.split("-")
@ -73,6 +74,15 @@ def interpret_bet(on="red", amount=0, bet=None):
assert col in list(range(0,3))
NUMS = {i for i in range(1, 37) if (i-1) % 3 == col}
div = 12
elif other_bet[0] == "split": # TODO: validate choices
num_1, num_2 = int(other_bet[1]), int(other_bet[2])
NUMS = {num_1, num_2}
div = 2
elif other_bet[0] == "corner": # TODO: validate choices
num_1, num_2 = int(other_bet[1]), int(other_bet[2])
num_3, num_4 = int(other_bet[3]), int(other_bet[4])
NUMS = {num_1, num_2, num_3, num_4}
div = 4
else:
raise ValueError("unsupported bet")
@ -82,12 +92,54 @@ def interpret_bet(on="red", amount=0, bet=None):
bet = init_bet()
bet = place_bet(bet, 21, 20)
#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])
#bet = interpret_bet("street-1", 3, bet)
#bet = interpret_bet("street-10", 3, bet)
#bet = interpret_bet("col-1", 12, bet)
# james bond
bet = place_bet(bet, 0, 1)
for n in range(13,19):
bet = place_bet(bet, n, 5)
bet = interpret_bet("19-36", 14, bet)
#print(bet[21])
import numpy as np
def expected(bet) -> float:
bets = np.array(list(bet.values()))
cond_bets = bets[bets > 0]
amt = sum(bets)
payout = amt*36/38
print(f"bet {amt:.2f} to win {payout:.2f}: {payout/amt:2.4f} with std {np.std(bets*36)} mean win of {36*np.mean(cond_bets)} {sum(bets>0)}/38 times.")
return payout
print("bond")
print(bet)
print(expected(bet))
print()
print("unknown")
bet = init_bet()
bet = interpret_bet("1-12", 15, bet)
bet = interpret_bet("13-24", 15, bet)
bet = interpret_bet("corner-26-27-29-30", 5, bet)
bet = interpret_bet("corner-32-33-35-36", 5, bet)
print(bet)
print(expected(bet))
print()
print("singles")
bet = init_bet()
bet = place_bet(bet, 21, 40)
#bet = place_bet(bet, 1, 1)
print(expected(bet))
print()
print("stupid")
bet = init_bet()
bet = interpret_bet("odd", 18, bet)
bet = interpret_bet("even", 18, bet)
#bet = place_bet(bet, -1, 1)
#bet = place_bet(bet, 0, 1)
print(expected(bet))