146 lines
4.4 KiB
Python
146 lines
4.4 KiB
Python
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)],
|
|
*[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", "first-half", "last-half", "second-half", "first-18", "last-18", "second-18"}
|
|
|
|
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 `{on}` 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(1,37) if i % 2 == 0}
|
|
if on in ("even", "evens"):
|
|
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 ("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(int(low), int(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
|
|
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")
|
|
|
|
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)
|
|
|
|
# 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))
|