Example #1
0
    def test_received_passed_cards_first_pass_valid(self, has_everyone_passed):
        pr = self.pr
        pr.id = 1
        pr.active = True
        pr.seats_received = []
        pr.passed_cards = []
        pr.save()

        pass_cards = (
            [Card(2, Card.CLUBS), Card(3, Card.CLUBS), Card(4, Card.CLUBS)])

        player = self.player
        player.id = 2
        player.position = 0
        player.hand = pass_cards
        player.save()

        has_everyone_passed.return_value = False

        pass_round.received_passed_cards(pass_cards, 2, 1)

        pr.refresh_from_db()

        self.assertListEqual(pass_cards, pr.passed_cards)
        self.assertListEqual([0], pr.seats_received)
    def test_card_discarded_invalid_trick_id(self, send_turn_notification,
                                             finish, send_players_discard):
        old_hand = [Card(2, Card.CLUBS)]
        time_turn_started = timezone.make_aware(
            datetime.datetime(2017, 10, 1, 0, 0, 0, 0))
        time_turn_ended = timezone.make_aware(
            datetime.datetime(2017, 10, 1, 0, 0, 4, 0))

        tt = self.tt
        tt.id = 9
        tt.active = True
        tt.discards = []
        tt.save()

        player = self.player
        player.id = 2
        player.position = 0
        player.hand = old_hand
        player.bank_ms = 10000
        player.time_turn_started = time_turn_started
        player.save()

        discard = Card(2, Card.CLUBS)
        trick_turn_rules.card_discarded(discard, 2, 1, time_turn_ended)

        tt.refresh_from_db()
        player.refresh_from_db()

        self.assertListEqual([], tt.discards)
        self.assertEqual(0, tt.expected_seat)

        self.assertListEqual(old_hand, player.hand)
        self.assertEqual(10000, player.bank_ms)
Example #3
0
    def test_received_passed_cards_pass_round_wrong_card_amount_invalid(self):
        pr = self.pr
        pr.id = 1
        pr.active = True
        pr.seats_received = []
        pr.passed_cards = []
        pr.save()

        pass_cards = (
            [Card(5, Card.CLUBS), Card(6, Card.CLUBS), Card(7, Card.CLUBS)])

        player = self.player
        player.id = 2
        player.position = 1
        player.save()

        pass_cards = [Card(5, Card.CLUBS)]

        pass_round.received_passed_cards(pass_cards, 2, 1)

        pr.refresh_from_db()

        expected_cards = []
        self.assertListEqual(expected_cards, pr.passed_cards)
        self.assertListEqual([], pr.seats_received)
Example #4
0
def pass_cards_selected(game, cards_str, player, turn_id):
    '''Called when a player selects which cards to pass
    
    Arguments:
        game: the game database entry
        cards_str: a string shorthand representing which cards the player chose
            to pass
        player: the database entry for the player who is passing their cards
        turn_id: the id of the current turn
    '''
    cards = Card.list_from_str_list(cards_str)
    pass_round.received_passed_cards(game, player, cards, turn_id)
def valid_cards_leader(tt, hand):
    valid_cards = []
    if tt.number == 0:
        valid_cards.append(Card(2, 'Clubs'))
    else:
        if tt.hearts_broken:
            valid_cards = hand
        else:
            for card in hand:
                if card.suit != Card.HEARTS:
                    valid_cards.append(card)
            if len(valid_cards) == 0:
                valid_cards = hand
    return valid_cards
Example #6
0
def trick_cards_selected(game, cards_str, player, turn_id):
    '''Called when a player selects which card to play for the trick turn
    
    Arguments:
        game: the game database entry
        cards_str: a string shorthand representing which cards the player chose
            to pass
        player: the database entry for the player who is passing their cards
        turn_id: the id of the current turn
    '''
    cards = Card.list_from_str_list(cards_str)
    # The assumption is that the player can only select one card on their turn
    # for the trick.
    card = cards[0]
    trick_turn.card_discarded(game, player, card, turn_id)
def send_delay_message(tt, player, turn_id, valid_cards):
    received_cards = []
    random_number = rn.randint(0, len(valid_cards) - 1)
    received_cards.append(valid_cards[random_number])
    delay_message = {
        'channel': 'game_command',
        'delay': 1000,  #250
        'content': {
            'command': 'trick_card_selected',
            'command_args': {
                'received_cards': Card.list_to_str_list(received_cards),
                'turn_id': turn_id,
                'player_id': player.id
            }
        }
    }
    Channel('asgi.delay').send(delay_message)
Example #8
0
def send_delay_message(pr, player, turn_id):
    received_cards = []
    random_numbers = rn.sample(range(0,13),3)
    for random_number in random_numbers:
        received_cards.append(player.hand[random_number])
    received_cards.sort()
    delay_message = {
        'channel':'game_command',
        'delay':250,
        'content':{
            'command':'pass_cards_selected',
            'command_args':{
                'received_cards': Card.list_to_str_list(received_cards),
                'turn_id': turn_id,
                'player_id': player.id
            }
        }
    }
    Channel('asgi.delay').send(delay_message)
def send_delay_message(tt, player, turn_id, valid_cards):
    received_cards = []
    random_number = rn.randint(0,len(valid_cards)-1)
    received_cards.append(valid_cards[random_number])
    if player.type == PlayerType.DUMMY:
        delay = 300
    else:
        delay = player.bank_ms + TRICK_BASE_MS
    delay_message = {
        'channel':'game_command',
        'delay':delay,
        'content':{
            'command':'trick_card_selected',
            'command_args':{
                'received_cards': Card.list_to_str_list(received_cards),
                'turn_id': turn_id,
                'player_id': player.id
            }
        }
    }
    Channel('asgi.delay').send(delay_message)
Example #10
0
def send_delay_message(pr, player, turn_id):
    received_cards = []
    random_numbers = rn.sample(range(0, 13), 3)
    for random_number in random_numbers:
        received_cards.append(player.hand[random_number])
    received_cards.sort()
    if player.type == PlayerType.DUMMY:
        delay = 100
    else:
        delay = PASS_ROUND_TIMEOUT_MS
    delay_message = {
        'channel': 'game_command',
        'delay': delay,
        'content': {
            'command': 'pass_cards_selected',
            'command_args': {
                'received_cards': Card.list_to_str_list(received_cards),
                'turn_id': turn_id,
                'player_id': player.id
            }
        }
    }
    Channel('asgi.delay').send(delay_message)
def send_player_valid_cards(gr, player, valid_cards):
    cards_str = Card.list_to_str(valid_cards)
    game_transmit(Channel(player.channel), {"valid_cards": cards_str})
def send_players_their_cards(gr):
    '''Sends a message to each player telling them which cards are 
    theirs'''
    for player in gr.game.player_set.all():
        cards_str = Card.list_to_str(player.hand)
        game_transmit(Channel(player.channel), {"Cards": cards_str})
def what_seat_has_two_of_clubs(gr):
    two_of_clubs = Card(2, 'Clubs')
    for player in gr.game.player_set.all():
        if two_of_clubs in player.hand:
            return player.position
Example #14
0
    def test_received_passed_cards_middle_pass_valid(self, has_everyone_passed):
        pr = self.pr
        pr.id = 1
        pr.active = True
        pr.seats_received = [0, 2]
        pr.passed_cards = [Card(2, Card.CLUBS), Card(3, Card.CLUBS),
                           Card(4, Card.CLUBS), Card(8, Card.CLUBS),
                           Card(9, Card.CLUBS), Card(10, Card.CLUBS)]
        pr.save()

        pass_cards = (
            [Card(5, Card.CLUBS), Card(6, Card.CLUBS), Card(7, Card.CLUBS)])

        player = self.player
        player.id = 2
        player.position = 1
        player.hand = pass_cards
        player.save()

        has_everyone_passed.return_value = False


        pass_round.received_passed_cards(pass_cards, 2, 1)

        pr.refresh_from_db()

        expected_cards = [Card(2, Card.CLUBS), Card(3, Card.CLUBS),
                          Card(4, Card.CLUBS), Card(5, Card.CLUBS),
                          Card(6, Card.CLUBS), Card(7, Card.CLUBS),
                          Card(8, Card.CLUBS), Card(9, Card.CLUBS),
                          Card(10, Card.CLUBS)]
        self.assertListEqual(expected_cards, pr.passed_cards)
        self.assertListEqual([0, 1, 2], pr.seats_received)
 def from_db_value(self, value, expression, connection, context):
     if value is None:
         return None
     return Card.list_from_str(value)
 def to_python(self, value):
     if value is None:
         return None
     return Card.list_from_str(value)
 def get_prep_value(self, value):
     return Card.list_to_str(value)