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 make_ticket(minimum_amount, maximum_amount, minimum_to_win):
    ticket = Ticket(ComboType.SIMPLE)
    ranges = ticket.ticket_ranges
    # for key, value in ranges.items():
    combo_types = ranges["combo_type"]
    bet_types = ranges["bet_type"]

    combo_type = combo_types[random.randint(0, len(combo_types) + 1)]
    random_ticket = Ticket(combo_type)

    amount = [1, 0.5][random.randint(0, 2)]
    if combo_type == ComboType.SIMPLE:
        bet_type = bet_types[random.randint(0, len(bet_types) + 1)]
        if bet_type == BetType.STRAIGHT:
            random_ticket.add_bet(bet_type, 1)
    elif combo_type == ComboType.THREE_WAY_COMBINATION:
        random_ticket.add_three_way_combo(1)
    elif combo_type == ComboType.SIX_WAY_COMBINATION:
        random_ticket.add_six_way_combo(1)
    elif combo_type == ComboType.STRAIGHT_BOX_THREE_WAY:
        random_ticket.add_three_way_box_combo(0.5)
    elif combo_type == ComboType.STRAIGHT_BOX_SIX_WAY:
        random_ticket.add_six_way_box_combo(0.5)
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())