def test_simulator_session(self): simulation_wheel = Wheel(1) simulation_table = Table(100,simulation_wheel) simulation_player = Martingale(simulation_table) simulation_player.set_rounds(self.simulator.init_duration) simulation_player.set_stake(self.simulator.init_stake) black = simulation_player.black #Martingale always bets on black simulated_stakes = [simulation_player.stake] while simulation_player.playing(): simulation_player.place_bets() outcome = simulation_wheel.next() if black in outcome: simulation_player.win(simulation_table.bets[0]) else: simulation_player.lose(simulation_table.bets[0]) simulation_table.clear_bets() simulated_stakes.append(simulation_player.stake) stakes = self.simulator.session() assert type(stakes) == list assert stakes == simulated_stakes
class TestTable: '''Tests that InvalidBet Exception is thrown when table enters invalid state. Invalid states are when: 1. Sum of bets exceeds table limit. 2. Bet amount is below table minimum. ''' def setup_method(self, method): wheel = Wheel() self.table = Table(100, wheel) def test_invalid_bet(self): with pytest.raises(InvalidBet): self.table.place_bet(Bet(105, Outcome("0", 35))) table2 = Table(100, self.table.wheel) table2.place_bet(Bet(60, Outcome("0", 35))) with pytest.raises(InvalidBet): self.table.place_bet(Bet(50, Outcome("0", 35))) def test_add_bet(self): bet = Bet(60, Outcome("0", 35)) self.table.place_bet(bet) assert bet == next(iter(self.table)) def test_table_clear_bet(self): self.table.place_bet(Bet(60, Outcome("0", 35))) assert len(self.table.bets) == 1 self.table.clear_bets() assert len(self.table.bets) == 0
from roulette import Game, Passenger57, PlayerEven, Table, Wheel, BinBuilder if __name__ == '__main__': TABLE_MIN = 10 table = Table(500, TABLE_MIN) wheel = Wheel() BinBuilder().build_bins(wheel) game = Game(wheel, table) playr = PlayerEven() playr.wallet = 10000 round = 1 while playr.is_playing() and playr.get_wallet() > TABLE_MIN: print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') print(f'Round {round}: player wallet is {playr.get_wallet()}') game.cycle(playr) round += 1 table.clear_bets() if playr.is_playing() is False: print(f"Thanks for playing: player final wallet is {playr.get_wallet()} {playr.is_playing()}") else: print(f"GAME OVER: player final wallet is {playr.get_wallet()} {playr.is_playing()}")