Example #1
0
 def _process_solve(self):
     cube_time = self._convert_cube_time()
     result = NewCubeCasino(cube_time).gamble()
     CubeBet.purge()
     result = CubeCasinoFormatter(result).format()
     print(f"Result from formatter: {result}")
     return result
Example #2
0
 def test_all_bets(self):
     result = CubeBet.all_bets()
     assert result == []
     CubeBet("carti", 32).save()
     result = CubeBet.all_bets()
     assert result == [("carti", 32, [])]
     CubeBet("uzi", 24).save()
     result = CubeBet.all_bets()
     assert result == [("uzi", 24, []), ("carti", 32, [])]
 def test_expensive_command(self):
     Command("damn").save()
     Command("damn").set_value("cost", 10)
     CubeBet("uzi", 45, ["damn"]).save()
     CubeBet("ella", 38, ["8bitrickroll", "hello"]).save()
     CubeBet("miles", 36, ["handbag"]).save()
     result = NewCubeCasino(37).gamble()
     assert result == [
         ("miles", "ella", "hello"),
     ]
Example #4
0
 def test_simple_bet(self):
     User("wayne.shorter").save()
     Command("smooth").allow_user("wayne.shorter")
     result = NewCubeCasinoRouter("wayne.shorter", "bet", ["42"]).route()
     assert CubeBet.count() == 1
     last_bet = CubeBet.last()
     assert last_bet["wager"] == ["smooth"]
     assert last_bet["user"] == "wayne.shorter"
     result = NewCubeCasinoRouter("beginbotbot", "all_bets").route()
     assert result == "@wayne.shorter: 42"
Example #5
0
    def route(self):
        if self.command == "bet":
            return self._process_bet()

        elif self.command == "cubed" and self.user == "beginbotbot":
            return self._process_solve()

        elif self.command in ["all_bets", "all_bet", "bets"]:
            return " | ".join([f"@{bet[0]}: {bet[1]}" for bet in CubeBet.all_bets()])

        elif self.command == "new_cube" and self.user == "beginbotbot":
            return CubeBet.purge()
Example #6
0
    def _match_winners_and_losers(self):
        all_bets = CubeBet.all_bets()
        winners, loser_commands, winning_bet = self._find_winners_and_losers(all_bets)

        winner_names = " ".join([f"@{winner[0]}" for winner in winners])
        send_twitch_msg(f"Winners: {' | '.join(winner_names)}")

        transfer_of_wealth = []

        # We have to sort winners by their bet amount
        for winner in winners:
            user, bet, wager = winner
            bet_amount = sum([Command(command).cost() for command in wager])
            commands_to_win = [
                loser for loser in loser_commands if loser[2] <= bet_amount
            ]

            while bet_amount > 0 and len(commands_to_win) > 0:
                random.shuffle(commands_to_win)
                command_tuple = commands_to_win.pop()

                # We remove the Command, so others Winners can't win it
                loser_commands.remove(command_tuple)
                loser, command, cost = command_tuple
                bet_amount -= cost
                transfer_obj = (user, loser, command)
                print(f"Transfer Obj: {transfer_obj}")
                transfer_of_wealth.append(transfer_obj)

        return transfer_of_wealth
    def _process_bet(self):
        parser = CubeCasinoParser(user=self.user,
                                  command=self.command,
                                  args=self.args).parse()

        if NewCubeCasino.is_stopwatch_running():
            return f"NO BETS WHILE BEGINBOT IS SOLVING"

        wager = parser.wager
        if wager == []:
            wager = User(self.user).commands()

        if wager:
            result = CubeBet(user=self.user, duration=parser.bet,
                             wager=wager).create_or_update()
            return f"@{self.user} Thank you for your bet: {parser.bet}s - {len(wager)} Commands"
        else:
            return f"@{self.user} you must own at least 1 soundeffect to bet!"
Example #8
0
    def _find_winners_and_losers(
        self, ) -> Tuple[List[Bet], List[Tuple[str, str, int]], int]:
        all_bets = CubeBet.all_bets()

        # Start with huge winning duration
        # and then update as we find closer examples
        winning_duration: int = 1000
        exact_winners = [bet for bet in all_bets if bet[1] == self._solve_time]
        winner_names = [winner[0] for winner in exact_winners]

        if exact_winners:
            print(f"\nExact Winners: {winner_names}\n")
            losers = [bet for bet in all_bets if bet[0] not in winner_names]
            winners = exact_winners
            winning_duration = self._solve_time
        else:
            for user, guess, _ in all_bets:
                bet_diff = int(guess) - self._solve_time
                print(f"@{user} Bet Diff: {bet_diff}")

                current_diff = winning_duration - self._solve_time
                if abs(bet_diff) < abs(current_diff):
                    winning_duration = guess

            winners = [bet for bet in all_bets if bet[1] == winning_duration]
            winner_names = [winner[0] for winner in winners]
            print(f"\nCloset Winners: {winner_names}\n")
            losers = [bet for bet in all_bets if bet[0] not in winner_names]

        loser_commands: List[Tuple[str, str, int]] = []
        for loser in losers:
            user, bet, wager = loser
            for command in wager:
                loser_command = (user, command, Command(command).cost())
                loser_commands.append(loser_command)

        print(f"Winners: {winner_names}\n")
        loser_names = [loser[0] for loser in losers]
        print(f"Losers: {loser_names}\n")

        return (winners, loser_commands, winning_duration)
 def test_with_multiple_winners(self):
     CubeBet("ella", 45, ["8bitrickroll", "hello"]).save()
     CubeBet("uzi", 36, ["damn"]).save()
     CubeBet("miles", 36, ["handbag"]).save()
     result = NewCubeCasino(37).gamble()
     assert result == [("uzi", "ella", "hello"), ("miles", "ella", "8bitrickroll")]
Example #10
0
 def test_a_wager(self):
     result = CubeBet("carti", 32, ["clap"]).save()
     assert result["wager"] == ["clap"]
Example #11
0
    def test_betting(self):
        name = self._create_user("gucci.mane")
        duration = 29
        subject = CubeBet(name.name, duration)
        assert CubeBet.count() == 0
        subject.save()
        assert CubeBet.count() == 1

        subject = CubeBet(name.name, 38)
        subject.save()

        assert CubeBet.count() == 1
        assert subject.duration() == 38