From 89dedfb52b46a14761b5a94ad0145d6837e45574 Mon Sep 17 00:00:00 2001 From: nova-rey Date: Mon, 3 Nov 2025 10:22:47 -0600 Subject: [PATCH] fix: use table.fixed_run for full roll execution in example script --- crapssim/strategy/odds.py | 14 +++++++++++--- crapssim/table.py | 10 +++++++++- examples/run_examples.py | 5 ++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/crapssim/strategy/odds.py b/crapssim/strategy/odds.py index c997feae..3ecf3fb5 100644 --- a/crapssim/strategy/odds.py +++ b/crapssim/strategy/odds.py @@ -1,6 +1,7 @@ +import numbers import typing -from crapssim.bet import Bet, Come, DontCome, DontPass, Odds, PassLine +from crapssim.bet import Bet, Come, DontCome, DontPass, Odds, PassLine, Put from crapssim.strategy.tools import Player, Strategy, Table @@ -148,8 +149,13 @@ def __init__( self.base_type = base_type self.always_working = always_working - if isinstance(odds_multiplier, int): - self.odds_multiplier = {x: odds_multiplier for x in (4, 5, 6, 8, 9, 10)} + if isinstance(odds_multiplier, numbers.Real): + multiplier_value = float(odds_multiplier) + if multiplier_value.is_integer(): + multiplier_value = int(multiplier_value) + self.odds_multiplier = { + x: multiplier_value for x in (4, 5, 6, 8, 9, 10) + } else: self.odds_multiplier = odds_multiplier @@ -159,6 +165,8 @@ def get_point_number(bet: Bet, table: "Table"): return table.point.number elif isinstance(bet, (Come, DontCome)): return bet.number + elif isinstance(bet, Put): + return bet.number else: raise NotImplementedError diff --git a/crapssim/table.py b/crapssim/table.py index a288e543..ea094f62 100644 --- a/crapssim/table.py +++ b/crapssim/table.py @@ -4,7 +4,7 @@ from crapssim.dice import Dice -from .bet import Bet, BetResult, DicePair +from .bet import Bet, BetResult, DicePair, Odds, Put from .point import Point from .strategy import BetPassLine, Strategy @@ -154,6 +154,14 @@ def update_numbers(table: "Table", verbose: bool) -> None: bet.update_number(table) table.point.update(table.dice) + if table.point != "On": + for player in table.players: + for bet in player.bets[:]: + if isinstance(bet, Put) or ( + isinstance(bet, Odds) and bet.base_type is Put + ): + player.remove_bet(bet) + if verbose: print(f"Point is {table.point.status} ({table.point.number})") diff --git a/examples/run_examples.py b/examples/run_examples.py index 1256bf93..99ed3d5c 100644 --- a/examples/run_examples.py +++ b/examples/run_examples.py @@ -1,4 +1,4 @@ -from crapssim.table import Table, TableUpdate +from crapssim.table import Table from crapssim.strategy.examples import ( QuickProps, BuySampler, @@ -19,8 +19,7 @@ def run_example(name, strategy_factory): player = table.add_player() player.strategy = strategy_factory() - for die_one, die_two in ROLLS: - TableUpdate.roll(table, fixed_outcome=(die_one, die_two), verbose=False) + table.fixed_run(dice_outcomes=ROLLS, verbose=False) print(f"Final bankroll: {player.bankroll:.2f}") # Show remaining open bets (should be few or none in these demos)