diff --git a/roulette.py b/roulette.py index 55a873e..81aeb05 100644 --- a/roulette.py +++ b/roulette.py @@ -1,17 +1,23 @@ from typing import List, Dict, Optional from functools import reduce from dataclasses import dataclass, field +from random import choice, randint + Bet = Dict[int, float] +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"] + *["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} @@ -93,7 +99,11 @@ def interpret_bet(on="red", amount=0, bet=Optional[Bet]): NUMS = {num_1, num_2, num_3, num_4} div = 4 else: - raise ValueError("unsupported bet") + try: + NUMS = {int(on)} + div = 1 + except ValueError as e: + raise e(f"Bet `{on}` not understood. Choose from feasible moves:\n {set(range(-1, 37))}") bet = reduce(lambda bet, num: place_bet(bet, num, amount / div), NUMS, bet) @@ -143,7 +153,7 @@ def place_bets(placements): return reduce(lambda bet, placement: combine_bets(bet, placement.place_bet()), placements, {}) # create a list of random Placements -from random import choice, randint + placements = [Placement(randint(1, 10), 1, choice(list(FEASIBLE_MOVES))) for _ in range(10)] @@ -172,7 +182,12 @@ class Strategy: # guarantees the max bet cannot exceed budget: num = randint(1, budget // amt) # select random bet type - on = choice(list(FEASIBLE_MOVES)) + # todo: consider if this is the logic you want... + if randint(0, 1) == 0: + on = choice(list(FEASIBLE_MOVES)) + else: + on = choice(list(SINGLE_BETS)) + on = choice(list(FEASIBLE_MOVES)) # todo: make a parameter, allow for just single bets. placement = Placement(num, amt, on) placements.append(placement) budget -= placement.value @@ -265,9 +280,10 @@ def simulate_games( return players + losers - +import ast # generate players and print them out players = generate_players(num_players=3, min_num_games=4, total_budget=200) +players[0] = Player(budget=200.0, strategy=Strategy(budget=50, placements=[Placement(num=2, amt=5, on='triple-00'), Placement(num=1, amt=10, on='col-1'), Placement(num=60, amt=0.25, on='corner-23-24-26-27'), Placement(num=10, amt=1, on='14'), Placement(num=1, amt=5, on='street-2')])) for p in players: print(p,'\n')