示例#1
0
 def test_bet_new_player(self):
     tim = timba.timba()
     # id 666 isn't in data
     minqlx_fake.countdown_game()
     new_player = minqlx_fake.Player(666, '*Cthugha*')
     minqlx_fake.call_command('!timba blue 1000', new_player)
     self.assertEqual({666: make_bet('blue', 1000)}, tim.get_current_bets())
示例#2
0
    def test_saves_credits_multiple_winners(self, m):
        tim = timba.timba()
        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
        minqlx_fake.call_command('!timba r 200', PLAYER_ID_MAP[11])
        minqlx_fake.call_command('!timba b 10', PLAYER_ID_MAP[12])
        minqlx_fake.call_command('!timba 4000 red', PLAYER_ID_MAP[13])

        # blue won. pot is 5210. 10 and 12 won.
        # original credits:
        #   10: 1000
        #   12: 5000 (empty)
        # winning percentages:
        #   10: 1000 / (1000 + 10) == 0.99..
        #   12: 10 / (1000 + 10) == 0.0099..
        # wins:
        #   10: 5210 * 0.99.. == round(5158.415841584158) == 5158
        #   12: 5210 * 0.0099.. == round(51.584158415841586) == 52
        self.run_game([10, 11], [12, 13], 7, 15)
        self.assertEqual(
            {
                10: 5158,  # original - bet + win == (1000 - 1000 + 5158)
                11: 1800,  # original - bet + win == (2000 - 200 + 0)
                12: 5042,  # original - bet + win == (5000 - 10 + 52)
                13: 1000  # original - bet + win == (5000 - 4000 + 0)
            },
            tim.get_credits())

        expected = {'10': 5158, '11': 1800, '12': 5042, '13': 1000}
        self.assertSavedJson(expected, m)
示例#3
0
    def test_bets_multiple_winners(self):
        tim = timba.timba()
        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 100', PLAYER_ID_MAP[10])
        minqlx_fake.call_command('!timba b 25', PLAYER_ID_MAP[11])
        minqlx_fake.call_command('!timba 875 red', PLAYER_ID_MAP[12])

        # blue won. pot is 1000. 10 and 11 won.
        # original credits:
        #   10: 1000
        #   11: 2000
        # winning percentages:
        #   10: 100 / (100 + 25) == 0.8
        #   11: 25 / (100 + 25) == 0.2
        # wins:
        #   10: 1000 * 0.8 == round(800) == 800
        #   12: 1000 * 0.2 == round(200) == 200
        self.run_game([10, 11], [12, 13], 7, 15)
        self.assertEqual(
            {
                10: 1700,  # original - bet + win == (1000 - 100 + 800)
                11: 2175,  # original - bet + win == (2000 - 25 + 200)
                12: 4125  # original - bet + win == (5000 - 875 + 0)
            },
            tim.get_credits())
示例#4
0
    def test_handles_game_start(self):
        tim = timba.timba()
        self.assertEqual({}, tim.get_current_bets())

        minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
        self.assertEqual({}, tim.get_current_bets())

        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
        minqlx_fake.call_command('!timba red 123', PLAYER_ID_MAP[11])
        expected_bets = {10: make_bet('blue', 1000), 11: make_bet('red', 123)}
        self.assertEqual(expected_bets, tim.get_current_bets())
        minqlx_fake.start_game(PLAYER_ID_MAP, [10, 11], [12, 13], 7, 15)
        TestTimba.fake_time += 1000
        minqlx_fake.frame()
        self.assertInMessages(
            'Betting is now closed. The pot is 1123 credits.')

        # should not be allowed
        minqlx_fake.call_command('!timba red 200', PLAYER_ID_MAP[10])
        self.assertEqual(expected_bets, tim.get_current_bets())
        minqlx_fake.end_game()

        # should not be allowed
        minqlx_fake.call_command('!timba red 200', PLAYER_ID_MAP[10])
        self.assertEqual({}, tim.get_current_bets())
示例#5
0
 def test_bet_no_args(self):
     tim = timba.timba()
     player = PLAYER_ID_MAP[10]
     player.clear_messages()
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
     self.assertEqual(['You have 1000 credits to bet.'], player.messages)
示例#6
0
 def test_bets_all_loser(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba red 1000', PLAYER_ID_MAP[10])
     minqlx_fake.call_command('!timba r 200', PLAYER_ID_MAP[11])
     # blue won
     self.run_game([10, 11], [12, 13], 7, 15)
     self.assertEqual({10: 0, 11: 1800}, tim.get_credits())
     self.assertInMessages('Everyone bet on the loser.')
示例#7
0
 def test_bet_invalid_args(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba bblue 1000', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
     minqlx_fake.call_command('!timba blue onemillion', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
     minqlx_fake.call_command('!timba blue one million', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
示例#8
0
 def test_bets_all_winner(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba red 1000', PLAYER_ID_MAP[10])
     minqlx_fake.call_command('!timba r 200', PLAYER_ID_MAP[11])
     # red won
     self.run_game([10, 11], [12, 13], 17, 15)
     self.assertEqual({10: 1000, 11: 2000}, tim.get_credits())
     self.assertInMessages(
         'When everyone wins, no one wins: everyone bet on the winner.')
示例#9
0
 def test_bets_not_enought(self):
     tim = timba.timba()
     player = PLAYER_ID_MAP[10]
     player.clear_messages()
     minqlx_fake.countdown_game()
     # 10 only has 1000 credits
     minqlx_fake.call_command('!timba blue 10000', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
     self.assertEqual(['You only have 1000 credits to bet.'],
                      player.messages)
示例#10
0
    def test_saves_credits_one_winner(self, m):
        tim = timba.timba()
        self.assertEqual(CREDITS_DATA, tim.get_credits())

        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
        # blue won
        self.run_game([10, 11], [12, 13], 7, 15)

        expected = copy.deepcopy(CREDITS_DATA)
        self.assertSavedJson(expected, m)
示例#11
0
 def test_bets_one_winner(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     new_player = minqlx_fake.Player(666, '*Cthugha*')
     minqlx_fake.Plugin.players_list.append(new_player)
     minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
     minqlx_fake.call_command('!timba r 200', PLAYER_ID_MAP[11])
     minqlx_fake.call_command('!timba 4000 red', new_player)
     # blue won. pot is 5200
     self.run_game([10, 11], [12, 13], 7, 15)
     self.assertEqual({10: 5200, 11: 1800, 666: 1000}, tim.get_credits())
示例#12
0
 def test_no_bets(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     # blue won
     minqlx_fake.Plugin.reset_log()
     self.assertEqual({}, tim.get_current_bets())
     minqlx_fake.start_game(PLAYER_ID_MAP, [10, 11], [12, 13], 7, 15)
     TestTimba.fake_time += 1000
     minqlx_fake.frame()
     self.assertMessages('Betting is now closed. There were no bets.')
     self.assertEqual({}, tim.get_current_bets())
示例#13
0
 def test_handles_game_end(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     new_player = minqlx_fake.Player(666, '*Cthugha*')
     minqlx_fake.Plugin.players_list.append(new_player)
     minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
     minqlx_fake.call_command('!timba red 200', PLAYER_ID_MAP[11])
     minqlx_fake.call_command('!timba blue 10', PLAYER_ID_MAP[12])
     minqlx_fake.call_command('!timba red 5000', PLAYER_ID_MAP[13])
     minqlx_fake.call_command('!timba red 4000', new_player)
     # blue won
     self.run_game([10, 11], [12, 13], 7, 15)
     self.assertInMessages('cthulhu :  1000 on blue')
     self.assertInMessages('nyarlathotep :    10 on blue')
     self.assertInMessages('shub niggurath :  -200 on red')
     self.assertInMessages('zoth-ommog : -5000 on red')
     self.assertInMessages('cthugha : -4000 on red')
示例#14
0
    def test_betting_window(self):
        tim = timba.timba()
        player = PLAYER_ID_MAP[10]
        player.clear_messages()
        minqlx_fake.Plugin.set_players_by_team({
            'red': [PLAYER_ID_MAP[13], PLAYER_ID_MAP[11]],
            'blue': [PLAYER_ID_MAP[12], PLAYER_ID_MAP[10]]
        })

        self.assertEqual({}, tim.get_current_bets())
        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 1000', player)
        self.assertEqual({10: make_bet('blue', 1000)}, tim.get_current_bets())
        self.assertEqual(('You bet 1000 credits on team blue. ' +
                          'You have 30 seconds to change your bet.'),
                         player.messages.pop())
        # 10 secs passed, we can still bet
        TestTimba.fake_time += 10
        minqlx_fake.frame()
        minqlx_fake.call_command('!timba red 1000', player)
        self.assertEqual({10: make_bet('red', 1000)}, tim.get_current_bets())
        self.assertEqual(('You bet 1000 credits on team red. ' +
                          'You have 20 seconds to change your bet.'),
                         player.messages.pop())
        # 29 secs passed, can still bet
        TestTimba.fake_time += 19
        minqlx_fake.frame()
        minqlx_fake.call_command('!timba red 100', player)
        self.assertEqual({10: make_bet('red', 100)}, tim.get_current_bets())
        self.assertEqual(('You bet 100 credits on team red. ' +
                          'You have 1 seconds to change your bet.'),
                         player.messages.pop())
        # 30 secs passed, bets closed
        TestTimba.fake_time += 1
        minqlx_fake.frame()
        self.assertInMessages('Betting is now closed. The pot is 100 credits.')
        self.assertEqual(('You bet 100 credits on team red. ' +
                          'You have 900 credits left. Good luck!'),
                         player.messages.pop())
        minqlx_fake.call_command('!timba red 1', player)
        self.assertEqual({10: make_bet('red', 100)}, tim.get_current_bets())
        self.assertEqual(
            'Betting is not allowed now. You have 900 credits to bet.',
            player.messages.pop())
示例#15
0
 def test_handles_game_countdown(self):
     tim = timba.timba()
     player = PLAYER_ID_MAP[10]
     player.clear_messages()
     self.assertEqual({}, tim.get_current_bets())
     # cannot bet until countdown
     minqlx_fake.call_command('!timba blue 1000', player)
     self.assertEqual({}, tim.get_current_bets())
     self.assertEqual(
         ['Betting is not allowed now. You have 1000 credits to bet.'],
         player.messages)
     minqlx_fake.countdown_game()
     self.assertInMessages(
         'Betting is now open: you have 30 seconds to place your bets!')
     minqlx_fake.call_command('!timba blue 1000', player)
     self.assertEqual({10: make_bet('blue', 1000)}, tim.get_current_bets())
     minqlx_fake.call_command('!timba red 200', player)
     self.assertEqual({10: make_bet('red', 200)}, tim.get_current_bets())
     minqlx_fake.call_command('!timba red 0', player)
示例#16
0
 def test_loads_credits_invalid_json(self):
     tim = timba.timba()
     self.assertEqual({}, tim.get_credits())
     # still usable
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba red 1000', PLAYER_ID_MAP[10])