Ejemplo n.º 1
0
    def test4(self):
        b = BinToGene()
        bin_list = [
            Bin("s", 0, 10, 0),
            Bin("s", 21, 30, 0),
            Bin("s", 31, 40, 0),
            Bin("s", 41, 50, 0),
            Bin("s", 71, 90, 0)
        ]

        result = b.binary_search(bin_list, 2, 13, True)
        assert result == 0
        result = b.binary_search(bin_list, 2, 13, False)
        assert result == 0

        result = b.binary_search(bin_list, 12, 22, True)
        assert result == 1
        result = b.binary_search(bin_list, 12, 22, False)
        assert result == 1

        result = b.binary_search(bin_list, 41, 62, True)
        assert result == 3
        result = b.binary_search(bin_list, 41, 62, False)
        assert result == 3
        result = b.binary_search(bin_list, 41, 92, False)
        assert result == 4

        result = b.binary_search(bin_list, 11, 20, True)
        assert result == -1
        result = b.binary_search(bin_list, 11, 20, False)
        assert result == -1
        result = b.binary_search(bin_list, 51, 60, True)
        assert result == -1
        result = b.binary_search(bin_list, 51, 60, False)
        assert result == -1
Ejemplo n.º 2
0
 def test2(self):
     b = Bin("s", 20, 60, 0)
     assert b.precedes(70, 90)
     assert not b.precedes(50, 90)
     assert not b.precedes(30, 40)
     assert not b.precedes(0, 30)
     assert not b.precedes(0, 10)
Ejemplo n.º 3
0
    def test1(self):
        b = BinToGene()
        bin_list = [
            Bin("s", 0, 10, 0),
            Bin("s", 11, 20, 0),
            Bin("s", 21, 30, 0),
            Bin("s", 31, 40, 0),
            Bin("s", 41, 50, 0)
        ]

        result = b.binary_search(bin_list, 2, 21, True)
        assert result == 0
        result = b.binary_search(bin_list, 12, 22, True)
        assert result == 1
        result = b.binary_search(bin_list, 22, 32, True)
        assert result == 2
        result = b.binary_search(bin_list, 32, 42, True)
        assert result == 3
        result = b.binary_search(bin_list, 42, 52, True)
        assert result == 4
        result = b.binary_search(bin_list, 12, 71, True)
        assert result == 1
        result = b.binary_search(bin_list, -10, 21, True)
        assert result == 0
        result = b.binary_search(bin_list, -10, 71, True)
        assert result == 0
        result = b.binary_search(bin_list, -20, -10, True)
        assert result == -1
        result = b.binary_search(bin_list, 61, 81, True)
        assert result == -1
    def test_bet_waits(self):
        red = Bin(Outcome("Red", 1))
        black = Bin(Outcome("Black", 1))

        for i in range(7):
            self.player.winners(red)
            self.assertEqual(self.player.stake, self.inital_player_stake)
        self.player.place_bets()
        self.assertEqual(self.player.stake,
                         self.inital_player_stake - self.table.min_limit)
Ejemplo n.º 5
0
    def test_initilaizer(self):
        bin_empty = Bin()
        self.assertEqual(str(bin_empty), "Bin()")

        bin_one_black = Bin([self.outcome_black1])
        self.assertEqual(str(bin_one_black), f"Bin({{{repr(self.outcome_black1)}}})")

        bin_two_outcomes = Bin([self.outcome_black1, self.outcome_straight5])
        expected_str = f"Bin({{{repr(self.outcome_straight5)}, {repr(self.outcome_black1)}}})"
        self.assertEqual(expected_str, str(bin_two_outcomes))
    def setUp(self):
        self.outcome1 = Outcome("abc", 2)
        self.outcome2 = Outcome("def", 3)
        self.outcome3 = Outcome("ghi", 4)
        self.outcome4 = Outcome("jkl", 5)

        self.bin1 = Bin(self.outcome1, self.outcome2, self.outcome3)
        self.bin2 = Bin(self.outcome2, self.outcome3, self.outcome4)

        self.wheel = Wheel(NonRandom())
        self.wheel.set_bin(0, self.bin1)
        self.wheel.set_bin(1, self.bin2)
    def test_bet_multiple(self):
        red = Bin(Outcome("Red", 1))
        black = Bin(Outcome("Black", 1))
        for i in range(4):
            for i in range(2):
                self.player.win(
                    Bet(Outcome("Black", 1), self.player.bet_multiple))
                print(self.player.bet_multiple)

            for j in range(3):
                self.player.lose(
                    Bet(Outcome("Black", 1), self.player.bet_multiple))
                print(self.player.bet_multiple)
Ejemplo n.º 8
0
 def test_choose(self):
     randomizer = random.Random()
     randomizer.seed(5)
     randomizeds = [randomizer.randint(0, 37) for _ in range(5)]
     self.wheel.random_generator.seed(5)
     for random_num in randomizeds:
         chosen_bin = self.wheel.choose()
         self.assertEqual(
             Bin([Outcome(f"some outcome{random_num}", random_num)]),
             chosen_bin)
Ejemplo n.º 9
0
    def test1(self):
        b = Bin("s", 20, 60, 0)
        assert b.intersects(-10, 30)
        assert b.intersects(30, 80)
        assert b.intersects(30, 50)
        assert b.intersects(10, 90)

        assert not b.intersects(-10, 0)
        assert not b.intersects(80, 100)
Ejemplo n.º 10
0
 def test3(self):
     b = Bin("s", 20, 60, 0)
     assert not b.suceeds(70, 90)
     assert not b.suceeds(50, 90)
     assert not b.suceeds(30, 40)
     assert not b.suceeds(0, 30)
     assert b.suceeds(0, 10)
Ejemplo n.º 11
0
def split_into_bins(data):
    """
    Splits the data into bins along each axis
    It creates floor(1 + log2(len(data))) bins for each axis
    
    Arguments:
    data - data array to split up into bins
    Returns: An array of bins for each dimension, number of bins per axis
    """

    bins = []
    for col_idx in range(len(data[0])):
        column_bins = []
        column_data = [x[col_idx] for x in data]
        col_min = min(column_data)
        col_max = max(column_data)

        interval_length = col_max - col_min
        # divide interval 1 + log2(n) bins
        nr_of_bins = math.floor(1 + math.log2(len(column_data)))

        column_bins = []
        b = interval_length / nr_of_bins
        for i in range(nr_of_bins):
            # adds a bin with a start and end interval
            bin_interval = Interval(col_min + b * i, col_min + b * (i + 1))

            column_bins.append(Bin(i, bin_interval, col_idx))

        # compute support for each bin
        for i, datapoint in enumerate(column_data):
            bin_index = int((datapoint - col_min) / b)
            bin_index = bin_index if bin_index < nr_of_bins else bin_index - 1
            column_bins[bin_index].add_point(data[i])

        bins.append(column_bins)
    return bins, nr_of_bins
    def build_bins(self, wheel):
        for i in range(0, len(wheel.bins)):
            wheel.set_bin(i, Bin())
        for i in range(1, 37):

            outcome = (self.generate_straight_bet(i), )

            wheel.add_outcome(i, outcome)

        for r in range(0, 12):
            # generate split bets
            first_col_no = 3 * r + 1
            outcome = (self.generate_split_bet(first_col_no, 1), )
            wheel.add_outcome(first_col_no, outcome)
            wheel.add_outcome(first_col_no + 1, outcome)
            second_col_no = 3 * r + 2
            outcome = (self.generate_split_bet(second_col_no, 1), )
            wheel.add_outcome(second_col_no, outcome)
            wheel.add_outcome(second_col_no + 1, outcome)

            # generate street bets
            n = 3 * r + 1
            outcome = (self.generate_street_bet(n), )
            wheel.add_outcome(n, outcome)
            wheel.add_outcome(n + 1, outcome)
            wheel.add_outcome(n + 2, outcome)

        for i in range(1, 34):
            # generate split bets
            outcome = (self.generate_split_bet(i, 3), )
            wheel.add_outcome(i, outcome)
            wheel.add_outcome(i + 3, outcome)

        for r in range(0, 11):
            # generate corner bets
            first_col_no = 3 * r + 1
            outcome = (self.generate_corner_bet(first_col_no), )
            wheel.add_outcome(first_col_no, outcome)
            wheel.add_outcome(first_col_no + 1, outcome)
            wheel.add_outcome(first_col_no + 3, outcome)
            wheel.add_outcome(first_col_no + 4, outcome)

            second_col_no = 3 * r + 2
            outcome = (self.generate_corner_bet(second_col_no), )
            wheel.add_outcome(second_col_no, outcome)
            wheel.add_outcome(second_col_no + 1, outcome)
            wheel.add_outcome(second_col_no + 3, outcome)
            wheel.add_outcome(second_col_no + 4, outcome)

            # generate line bets
            n = 3 * r + 1
            outcome = (self.generate_line_bet(n), )
            wheel.add_outcome(n, outcome)
            wheel.add_outcome(n + 1, outcome)
            wheel.add_outcome(n + 2, outcome)
            wheel.add_outcome(n + 3, outcome)
            wheel.add_outcome(n + 4, outcome)
            wheel.add_outcome(n + 5, outcome)

        for i in range(0, 3):
            # generate dozen bets
            outcome = (self.generate_dozen_bet(i + 1), )
            for j in range(0, 12):
                wheel.add_outcome(12 * i + j + 1, outcome)
        for i in range(0, 3):
            # generate column bets
            outcome = (self.generate_column_bet(r + 1), )
            for r in range(0, 12):
                wheel.add_outcome(3 * r + i + 1, outcome)

        # generate even money bets
        even_bets = {
            "Red": (self.generate_even_money_bet("Red"), ),
            "Black": (self.generate_even_money_bet("Black"), ),
            "Even": (self.generate_even_money_bet("Even"), ),
            "Odd": (self.generate_even_money_bet("Odd"), ),
            "High": (self.generate_even_money_bet("High"), ),
            "Low": (self.generate_even_money_bet("Low"), ),
        }
        for i in range(1, 37):
            if i < 19:
                wheel.add_outcome(i, even_bets["Low"])
            else:
                wheel.add_outcome(i, even_bets["High"])
            if i % 2 == 0:
                wheel.add_outcome(i, even_bets["Even"])
            else:
                wheel.add_outcome(i, even_bets["Odd"])
            if i in [
                    1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32,
                    34, 36
            ]:
                wheel.add_outcome(i, even_bets["Red"])
            else:
                wheel.add_outcome(i, even_bets["Black"])

        # generate 0 bets
        five_bet = (Outcome("Five Bet", 6), )
        wheel.add_outcome(0, (self.generate_straight_bet("0"), ))
        wheel.add_outcome(0, five_bet)
        wheel.add_outcome(-1, (self.generate_straight_bet("00"), ))
        wheel.add_outcome(-1, five_bet)
Ejemplo n.º 13
0
 def __init__(self):
     self.bins = tuple(Bin() for i in range(BIN_NUM))
     self.random_generator = random.Random()