def test_check_back_pair(): game = Game() ticket = Ticket(ComboType.SIMPLE) ticket.add_bet(BetType.BACK_PAIR, 1) ticket.set_chosen(123) for x in range(0, 10): assert game.check_ticket(ticket, int(str(x) + "23"))
def test_three_way_combo(): game = Game() ticket = Ticket(ComboType.THREE_WAY_COMBINATION) ticket.set_chosen(113) ticket.add_three_way_combo(1) for winner in [113, 311, 131]: ticket.set_chosen(winner) assert game.check_ticket(ticket, winner)
def test_check_front_pair(): game = Game() ticket = Ticket(ComboType.SIMPLE) ticket.add_bet(BetType.FRONT_PAIR, 1) ticket.set_chosen(123) for x in range(0, 10): draw = int("12" + str(x)) assert game.check_ticket(ticket, draw), (ticket._chosen, draw)
def test_straight_3_way_box_combo(): game = Game() ticket = Ticket(ComboType.SIMPLE) ticket.set_chosen(344) ticket.add_three_way_box_combo(0.5) price = ticket.price() ticket.check_valid() result = game.check_ticket(ticket, ticket._chosen) print(result)
def test_six_way_combo(): game = Game() ticket = Ticket(ComboType.SIX_WAY_COMBINATION) ticket.set_chosen(123) ticket.add_six_way_combo(0.5) six_winners = [123, 132, 213, 231, 312, 321] for winner in six_winners: ticket.set_chosen(winner) assert game.check_ticket(ticket, winner)
def test_straight_6_way_box_combo(): game = Game() ticket = Ticket(ComboType.SIMPLE) ticket.set_chosen(987) ticket.add_bet(BetType.SIX_WAY_BOX, .5) ticket.add_bet(BetType.STRAIGHT, 0.5) price = ticket.price() ticket.check_valid() result = game.check_ticket(ticket, ticket._chosen) print(result)
def test_straight(): game = Game() ticket = Ticket(ComboType.SIMPLE) ticket.add_bet(BetType.STRAIGHT, 1) for winner in range(0, 999): ticket.set_chosen(winner) assert game.check_ticket(ticket, winner) for winner in range(0, 999): if winner - 1 < 0 or winner - 1 > 999: continue ticket.set_chosen(winner - 1) assert not game.check_ticket(ticket, winner)
def test_check_three_way_box(): game = Game() ticket = Ticket(ComboType.SIMPLE) ticket.set_chosen(113) ticket.add_bet(BetType.THREE_WAY_BOX, 1) assert game.check_ticket(ticket, 311), game.check_ticket(ticket, 311) assert game.check_ticket(ticket, 131) assert game.check_ticket(ticket, 113) ticket.set_chosen(131) assert game.check_ticket(ticket, 311) assert game.check_ticket(ticket, 131) assert game.check_ticket(ticket, 113) ticket.set_chosen(311) assert game.check_ticket(ticket, 311) assert game.check_ticket(ticket, 131) assert game.check_ticket(ticket, 113) ticket.set_chosen(113) assert game.check_ticket(ticket, 111) assert game.check_ticket(ticket, 111) assert game.check_ticket(ticket, 111)
def test_check_six_way_box(): game = Game() ticket = Ticket(ComboType.SIMPLE) ticket.add_bet(BetType.SIX_WAY_BOX, 1) winners = [123, 132, 213, 312, 321] ticket.set_chosen(123) for winner in winners: assert game.check_ticket(ticket, winner) ticket.set_chosen(321) for winner in winners: assert game.check_ticket(ticket, winner) ticket.set_chosen(213) for winner in winners: assert game.check_ticket(ticket, winner) for winner in winners: if winner - 1 < 0 or winner - 1 > 999: continue ticket.set_chosen(winner - 1) if ticket._chosen.chosen in winners: continue assert not game.check_ticket(ticket, winner), (str( ticket._chosen), winner, game.check_ticket(ticket, winner))
def which_is_worst(rounds=100): worst_data = [] for combo in ComboType: if combo == ComboType.SIMPLE: continue game = Game() winnings = 0 gambled = 0 # sample ticket needs a number with a double or 3-way box's don't happen game_count = 0 win_count = 0 for i in range(0, rounds): ticket = Ticket(combo) if combo == ComboType.THREE_WAY_COMBINATION: ticket.set_chosen(113) ticket.add_three_way_combo(0.5) elif combo == ComboType.SIX_WAY_COMBINATION: ticket.set_chosen(123) ticket.add_six_way_combo(0.5) elif combo == ComboType.STRAIGHT_BOX_SIX_WAY: ticket.set_chosen(123) ticket.add_six_way_box_combo(0.5) elif combo == ComboType.STRAIGHT_BOX_THREE_WAY: ticket.set_chosen(113) ticket.add_three_way_box_combo(0.5) else: raise TypeError("Don't have this compo yet.") game_count += 1 for bet in ticket.bets: gambled += bet.amount drawing = game.draw_winner() bets_won = game.check_ticket(ticket, drawing) if bets_won: win_count += 1 prize = 0 for bet in bets_won: prize += ticket.payoffs(ticket.state, bet.bet_type, bet.amount) if isinstance(prize, list): winnings += prize[1] else: winnings += prize net = winnings - gambled try: percent_won = winnings / gambled except ZeroDivisionError: percent_won = "N/A" try: percent_by_count = win_count / game_count except ZeroDivisionError: percent_by_count = "N/A" try: odds = game_count / win_count except ZeroDivisionError: odds = "N/A" worst_data.append([ combo, winnings, gambled, gambled - winnings, "{0:.4f}".format(percent_won), "{0:.4f}".format(percent_by_count), "{0:.2f}".format(odds) ]) for bet_type in [ BetType.STRAIGHT, BetType.THREE_WAY_BOX, BetType.SIX_WAY_BOX, BetType.FRONT_PAIR, BetType.BACK_PAIR ]: ticket = Ticket(ComboType.SIMPLE) game = Game() winnings = 0 gambled = 0 # sample ticket needs a number with a double or 3-way box's don't happen game_count = 0 win_count = 0 ticket.add_bet(bet_type, 1) for i in range(0, rounds): game_count += 1 if bet_type in (BetType.THREE_WAY_BOX, ): ticket.set_chosen(113) if bet_type in (BetType.SIX_WAY_BOX, ): ticket.set_chosen(123) for bet in ticket.bets: gambled += bet.amount drawing = game.draw_winner() if game.check_ticket(ticket, drawing): win_count += 1 prize = 0 for bet in ticket.bets: prize += ticket.payoffs(ticket.state, bet.bet_type, bet.amount) if isinstance(prize, list): winnings += prize[1] else: winnings += prize net = winnings - gambled try: percent_won = winnings / gambled except ZeroDivisionError: percent_won = "N/A" try: percent_by_count = win_count / game_count except ZeroDivisionError: percent_by_count = "N/A" try: odds = game_count / win_count except ZeroDivisionError: odds = "N/A" worst_data.append([ bet_type, winnings, gambled, gambled - winnings, "{0:.4f}".format(percent_won), "{0:.4f}".format(percent_by_count), "{0:.2f}".format(odds) ]) t = Txtble() t.headers = [ "bet type", "winnigs", "gambled", "lost", "percent_won", "percent by count", "odds" ] for row in worst_data: t.append(row) print(t.show())