def test_column_bets(): bin_builder = BinBuilder() wheel = Wheel() bin_builder.gen_column_bets(wheel) assert wheel.get_bin(1).outcomes == frozenset([Outcome("Column 1", 2)]) assert wheel.get_bin(28).outcomes == frozenset([Outcome("Column 1", 2)]) assert wheel.get_bin(27).outcomes == frozenset([Outcome("Column 3", 2)])
def test_streets_bets(): bin_builder = BinBuilder() wheel = Wheel() bin_builder.gen_streets_bets(wheel) assert wheel.get_bin(1).outcomes == frozenset([Outcome("1, 2, 3", 17)]) assert wheel.get_bin(2).outcomes == frozenset([Outcome("1, 2, 3", 17)]) assert wheel.get_bin(3).outcomes == frozenset([Outcome("1, 2, 3", 17)])
def _cornerBets(self): """ Generating Corner Bets """ for r in range(11): # First Column Number n = 3 * r + 1 # Column 1-2 Corner corner = "{0}, {0} + 1, {0} + 3, {0} + 4".format(n) # Assign to Bins. for i in range(n, n + 5): self.wheel.bins[n].addOutcome( Outcome(corner, RouletteGame.cornerBet)) # self.wheel.bins[n+1].addOutcome(Outcome(corner, RouletteGame.cornerBet)) # self.wheel.bins[n+3].addOutcome(Outcome(corner, RouletteGame.cornerBet)) # self.wheel.bins[n+4].addOutcome(Outcome(corner, RouletteGame.cornerBet)) self.wheel.add(Outcome(corner, RouletteGame.cornerBet)) # Second Column Number n = 3 * r + 2 # Column 2-3 Corner corner = "{0}, {0} + 1, {0} + 3, {0} + 4".format(n) # Assign to Bins for i in range(n, n + 5): self.wheel.bins[i].addOutcome( Outcome(corner, RouletteGame.cornerBet)) # self.wheel.bins[n+1].addOutcome(Outcome(corner, RouletteGame.cornerBet)) # self.wheel.bins[n+3].addOutcome(Outcome(corner, RouletteGame.cornerBet)) # self.wheel.bins[n+4].addOutcome(Outcome(corner, RouletteGame.cornerBet)) self.wheel.add(Outcome(corner, RouletteGame.cornerBet))
def test_straight_bets(): bin_builder = BinBuilder() wheel = Wheel() bin_builder.gen_straight_bets(wheel) assert wheel.get_bin(0).outcomes == frozenset([Outcome("0", 35)]) assert wheel.get_bin(37).outcomes == frozenset([Outcome("00", 35)]) assert wheel.get_bin(3).outcomes == frozenset([Outcome("3", 35)])
def test_dozen_bets(): bin_builder = BinBuilder() wheel = Wheel() bin_builder.gen_dozen_bets(wheel) assert wheel.get_bin(1).outcomes == frozenset([Outcome("Dozen 1", 2)]) assert wheel.get_bin(13).outcomes == frozenset([Outcome("Dozen 2", 2)]) assert wheel.get_bin(36).outcomes == frozenset([Outcome("Dozen 3", 2)])
def setUp(self): self.first = Outcome('one', 17) self.second = Outcome('one', 17) self.third = Outcome('two', 32) self.fbin = Bin(self.first) self.sbin = Bin(self.second)
def test(self): oc1 = Outcome('1', 35) oc2 = Outcome('1', 17) oc3 = Outcome('2', 2) self.assertEqual(oc1, oc2) self.assertEqual(oc1.__hash__(), oc2.__hash__()) self.assertEqual(oc3.winAmount(50), 100)
def test_line_bets(): bin_builder = BinBuilder() wheel = Wheel() bin_builder.gen_line_bets(wheel) assert wheel.get_bin(1).outcomes == frozenset( [Outcome("1, 2, 3, 4, 5, 6", 5)]) assert wheel.get_bin(4).outcomes == frozenset( [Outcome("1, 2, 3, 4, 5, 6", 5), Outcome("4, 5, 6, 7, 8, 9", 5)])
def test_place_bet(): wheel = create_wheel() table = Table(wheel) zerozero = Outcome("00", 35) zerozero_bet = Bet(900, zerozero) red_bet = Bet(60, Outcome("Red", 1)) table.place_bet(zerozero_bet) table.place_bet(red_bet) assert [x.bet_amount for x in table] == [900, 60] with pytest.raises(InvalidBet): table.place_bet(red_bet)
def test_bin_has_outcomes(): outcome_0 = Outcome("0", 35) outcome_5 = Outcome("Five", 6) outcome_00 = Outcome("00", 35) bin_0 = Bin(0) bin_0.add(outcome_0) bin_0.add(outcome_5) bin_00 = Bin(37) bin_00.add(outcome_00) bin_00.add(outcome_5) assert bin_0.outcomes == frozenset([outcome_0, outcome_5]) assert bin_00.outcomes == frozenset([outcome_00, outcome_5])
def test_split_bet(self): bb.split_bet() for count, i in enumerate(bb.bins): udstart = count % 3 + 1 lrstart = udstart if udstart % 3 == 0: lrstart -= 1 self.assertTrue( Outcome(("%d-%d split" % (udstart, (udstart + 3))), 17), i) self.assertTrue( Outcome(("%d-%d split" % (lrstart, (lrstart + 1))), 17), i)
def _streetBets(self): """ Generating Street Bets """ street = "{0}, {0} + 1, {0} + 2" for r in range(12): n = 3 * r + 1 for i in range(n, n + 3): self.wheel.bins[n].addOutcome( Outcome(street.format(n), RouletteGame.streetBet)) # self.wheel.bins[n+1].addOutcome(Outcome(street.format(n), RouletteGame.streetBet)) # self.wheel.bins[n+2].addOutcome(Outcome(street.format(n), RouletteGame.streetBet)) self.wheel.add(Outcome(street.format(n), RouletteGame.streetBet))
def _lineBets(self): """ Generating Line Bets """ for r in range(11): # First Column Number n = 3 * r + 1 line = "{0}, {0} + 1, {0} + 2, {0} + 3, {0} + 4, {0} + 5".format(n) # Assign to Bins for i in range(n, n + 6): self.wheel.bins[n].addOutcome( Outcome(line, RouletteGame.lineBet)) self.wheel.add(Outcome(line, RouletteGame.lineBet))
def gen_streets_bets(self, wheel): for r in range(12): n = 3 * r + 1 outcome = Outcome("%i, %i, %i" % (n, (n + 1), (n + 2)), 11) wheel.add_outcome(n, outcome) wheel.add_outcome(n + 1, outcome) wheel.add_outcome(n + 2, outcome)
def test_run_the_wheel(): nrg = NonRandom([0, 37]) wheel = Wheel(nrg) outcome_0 = Outcome("0", 35) outcome_5 = Outcome("Five", 6) outcome_00 = Outcome("00", 35) wheel.add_outcome(0, outcome_0) wheel.add_outcome(0, outcome_5) wheel.add_outcome(37, outcome_00) wheel.add_outcome(37, outcome_5) bin = wheel.next() assert bin.outcomes == frozenset([outcome_0, outcome_5]) bin = wheel.next() assert bin.outcomes == frozenset([outcome_00, outcome_5])
def gen_line_bets(self, wheel): for r in range(10): line = list() for i in range(6): line.append(3 * r + 1 + i) outcome = Outcome(", ".join([str(x) for x in line]), 5) for bin in line: wheel.add_outcome(bin, outcome)
def get_outcome(self, name): if name in self.outcomes: return self.outcomes[name] elif name in self.AVAILABALE_OUTCOMES: self.outcomes[name] = Outcome(name, self.AVAILABALE_OUTCOMES[name]) return self.outcomes[name] else: raise Exception(name + ' outcome is not found')
def _columnBets(self): """ Generating Column Bets """ for c in range(3): column = "{} + 1".format(c) outcome = Outcome(column, 2) self.wheel.add(outcome) for r in range(12): self.wheel.bins[3 * r + c + 1].addOutcome(outcome)
def _dozenBets(self): """ Generating Dozen Bets """ for d in range(3): dozen = "{} + 1".format(d) outcome = Outcome(dozen, RouletteGame.dozenBet) self.wheel.add(outcome) for m in range(12): self.wheel.bins[(12 * d) + m + 1].addOutcome(outcome)
def gen_split_bets(self, wheel): # Horizontal splits: for r in range(12): # First column number: n = 3 * r + 1 # Column 1-2 split outcome = Outcome("%s, %s" % (n, n + 1), 17) wheel.add_outcome(n, outcome) wheel.add_outcome(n + 1, outcome) # Second column number: n = 3 * r + 2 # Column 2-3 split outcome = Outcome("%s, %s" % (n, n + 1), 17) wheel.add_outcome(n, outcome) wheel.add_outcome(n + 1, outcome) # Vertical splits: for i in range(1, 33): outcome = Outcome("%s, %s" % (i, i + 3), 17) wheel.add_outcome(i, outcome) wheel.add_outcome(i + 3, outcome)
def test_split_bets(): bin_builder = BinBuilder() wheel = Wheel() bin_builder.gen_split_bets(wheel) assert wheel.get_bin(1).outcomes == frozenset( [Outcome("1, 2", 17), Outcome("1, 4", 17)]) assert wheel.get_bin(20).outcomes == frozenset([ Outcome("17, 20", 17), Outcome("19, 20", 17), Outcome("20, 21", 17), Outcome("20, 23", 17), ]) assert wheel.get_bin(18).outcomes == frozenset([ Outcome("15, 18", 17), Outcome("17, 18", 17), Outcome("18, 21", 17), ])
def _evenMoneyBets(self): """ Generating Even-Money Bets """ evenMoneyBets = { "RED": Outcome("red", 1), "BLACK": Outcome("black", 1), "EVEN": Outcome("even", 1), "ODD": Outcome("odd", 1), "HIGH": Outcome("high", 1), "LOW": Outcome("low", 1) } bets = evenMoneyBets.values() for bet in bets: self.wheel.add(bet) RED_NUMS = frozenset({ 1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36 }) for n in range(1, 37): if n < 19: self.wheel.bins[n].addOutcome(evenMoneyBets["LOW"]) else: self.wheel.bins[n].addOutcome(evenMoneyBets["HIGH"]) if n % 2 == 0: self.wheel.bins[n].addOutcome(evenMoneyBets["EVEN"]) else: self.wheel.bins[n].addOutcome(evenMoneyBets["ODD"]) if n in RED_NUMS: self.wheel.bins[n].addOutcome(evenMoneyBets["RED"]) else: self.wheel.bins[n].addOutcome(evenMoneyBets["BLACK"])
class TestOutcome(unittest.TestCase): oc1 = Outcome("0", 35) oc2 = Outcome("1", 5) oc3 = Outcome("2", 1) oc4 = Outcome("red", 1) oc5 = Outcome("even", 1) oc6 = Outcome("odd", 1) def test_eq(self): self.assertEqual(TestOutcome.oc1.__eq__(TestOutcome.oc2), False, "Should be false.") def test_winAmount(self): self.assertEqual(TestOutcome.oc1.winAmount(2), 70, "Should be 70") def test_ne(self): self.assertEqual(TestOutcome.oc3.__ne__(TestOutcome.oc2), True, "Should be false.") def test_eq2(self): self.assertNotEqual(TestOutcome.oc1.__eq__(TestOutcome.oc3), True, "Should be not equal.") def test_str(self): self.assertEqual(TestOutcome.oc1.__str__(), "0 (35:1)", "Should be 0 (35:1)")
def test_corner_bets(): bin_builder = BinBuilder() wheel = Wheel() bin_builder.gen_corner_bets(wheel) assert wheel.get_bin(1).outcomes == frozenset([Outcome("1, 2, 4, 5", 8)]) assert wheel.get_bin(4).outcomes == frozenset([ Outcome("1, 2, 4, 5", 8), Outcome("4, 5, 7, 8", 8), ]) assert wheel.get_bin(7).outcomes == frozenset([ Outcome("4, 5, 7, 8", 8), Outcome("7, 8, 10, 11", 8), ]) assert wheel.get_bin(8).outcomes == frozenset([ Outcome("4, 5, 7, 8", 8), Outcome("5, 6, 8, 9", 8), Outcome("7, 8, 10, 11", 8), Outcome("8, 9, 11, 12", 8), ])
def test_state(self): noWins = Player1326NoWins(self.player) print(noWins.currentBet()) self.assertEqual(noWins.currentBet().__repr__(), Bet(1, Outcome('black', 1)).__repr__()) oneWin = noWins.nextWon() print(oneWin.currentBet()) twoWins = oneWin.nextWon() print(twoWins.currentBet()) threeWins = twoWins.nextWon() print(threeWins.currentBet())
def _splitBets(self): """ Generating Split Bets """ left_right = "{0}, {0} + 1" splitBet = RouletteGame.splitBet # Left-Right Pairs for r in range(12): n = 3 * r + 1 self.wheel.bins[n].addOutcome( Outcome(left_right.format(n), RouletteGame.splitBet)) self.wheel.bins[n + 1].addOutcome( Outcome(left_right.format(n), RouletteGame.splitBet)) self.wheel.add(Outcome(left_right.format(n), RouletteGame.splitBet)) n = 3 * r + 2 ## print("{} = 3 * {} + 2".format(n, r)) self.wheel.bins[n].addOutcome( Outcome(left_right.format(n), RouletteGame.splitBet)) self.wheel.bins[n + 1].addOutcome( Outcome(left_right.format(n), RouletteGame.splitBet)) self.wheel.add(Outcome(left_right.format(n), RouletteGame.splitBet)) n = 3 * r + 1 ## print("{} = 3 * {} + 1".format(n, r)) up_down = "{0}, {0} + 3" # Up-Down Pairs for n in range(1, 34): self.wheel.bins[n].addOutcome( Outcome(up_down.format(n), RouletteGame.splitBet)) self.wheel.bins[n + 3].addOutcome( Outcome(up_down.format(n), RouletteGame.splitBet)) self.wheel.add(Outcome(up_down.format(n), RouletteGame.splitBet))
def test_even_money_bets(): bin_builder = BinBuilder() wheel = Wheel() bin_builder.gen_even_money_bets(wheel) assert wheel.get_bin(1).outcomes == frozenset([ Outcome("Low", 1), Outcome("Odd", 1), Outcome("Red", 1), ]) assert wheel.get_bin(24).outcomes == frozenset([ Outcome("High", 1), Outcome("Even", 1), Outcome("Black", 1), ])
def _straighBets(self): """ Generating Straight Bets """ betOdds = RouletteGame.straightBet straight = "{}" self.wheel.add(Outcome(straight.format(0), betOdds)) self.wheel.bins[0].addOutcome(Outcome(straight.format(0), betOdds)) for n in range(1, 37): self.wheel.bins[n].addOutcome(Outcome(straight.format(n), betOdds)) self.wheel.add(Outcome(straight.format(n), betOdds)) self.wheel.bins[37].addOutcome(Outcome(straight.format("00"), betOdds)) self.wheel.add(Outcome(straight.format("00"), betOdds))
def gen_even_money_bets(self, wheel): red = Outcome("Red", 1) black = Outcome("Black", 1) even = Outcome("Even", 1) odd = Outcome("Odd", 1) high = Outcome("High", 1) low = Outcome("Low", 1) for n in range(1, 37): if n < 19: wheel.add_outcome(n, low) else: wheel.add_outcome(n, high) if n % 2 == 0: wheel.add_outcome(n, even) else: wheel.add_outcome(n, odd) if n in [ 1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 30, 32, 34, 36 ]: wheel.add_outcome(n, red) else: wheel.add_outcome(n, black)
def test_build(): bin_builder = BinBuilder() wheel = Wheel() bin_builder.build_bins(wheel) wheel.get_bin(13).outcomes == frozenset([ Outcome("13", 35), Outcome("10, 13", 17), Outcome("13, 14", 17), Outcome("13, 16", 17), Outcome("13, 14, 15", 11), Outcome("10, 11, 13, 14", 8), Outcome("13, 14, 16, 17", 8), Outcome("10, 11, 12, 13, 14, 15", 5), Outcome("13, 14, 15, 16, 17, 18", 5), Outcome("Dozen 1", 2), Outcome("Column 1", 1), Outcome("Low", 1), Outcome("Odd", 1), Outcome("Black", 1), ])