Esempio n. 1
0
    def test_deal_miss(self):
        # set up initial room state
        room = new_room_data(
            room_id='test',
            player_number=5,
        )

        for i in range(5):
            client = Client()
            username = '******'.format(i)
            player_data = new_player_data(
                username=username,
                reply=client.reply_channel,
                ready=True,
            )
            room['players'].append(player_data)
            cache.set('player-room:' + username, 'test')
            self.clients.append(client)
        room['game']['state'] = RoomState.BIDDING
        cache.set('room:test', room)

        self.deal(
            'doge0',
            ['SA', 'JK', 'S10', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8'])
        self.deal_miss('doge0')

        room = cache.get('room:test')
        self.assertIs(room['game']['state'], RoomState.NOT_PLAYING)
        from websocket.consumers.gameplay_consumers import gameplay_start_consumer
        message = self.get_next_message('gameplay-start', require=True)
        gameplay_start_consumer(message)

        room = cache.get('room:test')
        self.assertIs(room['game']['state'], RoomState.BIDDING)
Esempio n. 2
0
    def test_record_one(self):
        for i in range(5):
            create_user(username='******'.format(i),
                        password='******',
                        nickname='nick{}'.format(i),
                        email='*****@*****.**')
        # set up initial room state
        room = new_room_data(
            room_id='test',
            player_number=5,
        )

        for i in range(5):
            client = Client()
            username = '******'.format(i)
            player_data = new_player_data(
                username=username,
                reply=client.reply_channel,
                ready=True,
            )
            room['players'].append(player_data)
            cache.set('player-room:' + username, 'test')
            self.clients.append(client)
        room['game']['state'] = RoomState.BIDDING
        cache.set('room:test', room)

        self.floor_card(['SJ', 'C9', 'JK'])
        self.deal(
            'doge0',
            ['SA', 'SQ', 'S2', 'HJ', 'D6', 'DK', 'C10', 'D7', 'C7', 'D4'])
        self.deal(
            'doge1',
            ['SK', 'S8', 'H3', 'C4', 'H10', 'D8', 'S5', 'HK', 'C6', 'HQ'])
        self.deal(
            'doge2',
            ['CQ', 'H8', 'S7', 'S3', 'HA', 'CA', 'S10', 'D9', 'DQ', 'S4'])
        self.deal('doge3',
                  ['C2', 'H5', 'S9', 'DJ', 'H9', 'C8', 'D2', 'C5', 'DA', 'H4'])
        self.deal(
            'doge4',
            ['H2', 'H7', 'D3', 'CJ', 'CK', 'D10', 'H6', 'S6', 'C3', 'D5'])
        self.bid('doge0', 13, 'S', True)
        self.bid('doge1', 0, '', False)
        room = cache.get('room:test')
        self.assertIs(room['game']['state'], RoomState.BIDDING)
        self.bid('doge2', 0, '', False)
        self.bid('doge3', 0, '', False)
        self.bid('doge4', 0, '', False)
        room = cache.get('room:test')
        self.assertIs(room['game']['state'], RoomState.FRIEND_SELECTING)
        self.friend_select('doge0', {
            'type': 'card',
            'card': 'DA',
            'floor_cards': ['HJ', 'C10', 'C7'],
        })
        room = cache.get('room:test')
        self.assertIs(room['game']['state'], RoomState.PLAYING)
        # round 1
        self.play('doge0', 'DK')
        self.play('doge1', 'D8')
        self.play('doge2', 'D9')
        self.play('doge3', 'DJ')
        self.play('doge4', 'D3')
        # round 2
        self.play('doge0', 'SA')
        self.play('doge1', 'S5')
        self.play('doge2', 'S3')
        self.play('doge3', 'S9')
        self.play('doge4', 'S6')
        # round 3
        self.play('doge0', 'JK', joker_suit='S')
        self.play('doge1', 'S8')
        self.play('doge2', 'S7')
        self.play('doge3', 'C2')
        self.play('doge4', 'C3')
        # round 4
        self.play('doge0', 'S2')
        self.play('doge1', 'SK')
        self.play('doge2', 'S4')
        self.play('doge3', 'DA')
        self.play('doge4', 'H2')
        # round 5
        self.play('doge3', 'D2')
        self.play('doge4', 'D10')
        self.play('doge0', 'D4')
        self.play('doge1', 'H10')
        self.play('doge2', 'DQ')
        # round 6
        self.play('doge2', 'CA')
        self.play('doge3', 'C5')
        self.play('doge4', 'CJ')
        self.play('doge0', 'C9')
        self.play('doge1', 'C4')
        # round 7
        self.play('doge2', 'HA')
        self.play('doge3', 'H4')
        self.play('doge4', 'H6')
        self.play('doge0', 'SJ')
        self.play('doge1', 'H3')
        # round 8
        self.play('doge0', 'SQ')
        self.play('doge1', 'C6')
        self.play('doge2', 'S10')
        self.play('doge3', 'H5')
        self.play('doge4', 'H7')
        # round 9
        self.play('doge0', 'D7')
        self.play('doge1', 'HQ')
        self.play('doge2', 'H8')
        self.play('doge3', 'H9')
        self.play('doge4', 'D5')
        # final round
        self.play('doge0', 'D6')
        self.play('doge1', 'HK')
        self.play('doge2', 'CQ')
        self.play('doge3', 'C8')
        self.play('doge4', 'CK')
        ###
        room = cache.get('room:test')
        self.assertIs(room['game']['state'], RoomState.RESULT)
        self.assertEqual(room['players'][0]['username'], 'doge3')

        history = GameHistory.objects.get(id=1)
        self.assertEqual(history.bid, 13)
        self.assertEqual(history.giruda, 'S')
        self.assertEqual(history.president.username, 'doge0')
        self.assertEqual(history.friend.username, 'doge3')
        doge2 = User.objects.get(username='******')
        self.assertEqual(doge2.game_histories.all()[0], history)

        self.game_continue('doge0', True)
        self.game_continue('doge0', True)
        self.game_continue('doge1', True)
        self.game_continue('doge2', True)
        self.game_continue('doge3', True)
        room = cache.get('room:test')
        self.assertIs(room['game']['state'], RoomState.RESULT)
        self.game_continue('doge4', True)
        from websocket.consumers.gameplay_consumers import gameplay_start_consumer
        message = self.get_next_message('gameplay-start')
        gameplay_start_consumer(message)
        room = cache.get('room:test')
        self.assertIs(room['game']['state'], RoomState.BIDDING)