Ejemplo n.º 1
0
    def test_bigger_flush(self):
        for i in range(num_tests):
            cards_a = Stack()
            cards_b = Stack()
            suit = random.choice(SUITS[:2])
            values = random.sample(VALUES, 5)

            for value in values:
                cards_a.add(Card(value, suit))

            if get_cards_type(cards_a) == STRAIGHT_FLUSH:
                continue

            if suit == "Hearts":
                suit = "Spades"
            else:
                suit = random.choice(SUITS[(SUITS.index(suit) + 1):])

            values = random.sample(VALUES, 5)
            for value in values:
                cards_b.add(Card(value, suit))

            if get_cards_type(cards_b) == STRAIGHT_FLUSH:
                continue

            self.assertTrue(are_cards_bigger(cards_a, cards_b))
Ejemplo n.º 2
0
    def test_bigger_full_house(self):
        for i in range(num_tests):
            cards_a = Stack()
            cards_b = Stack()
            values = list(VALUES[1:])
            three_value = random.choice(values)
            index = values.index(three_value)
            values.remove(three_value)
            two_value = random.choice(values)

            for suit in random.sample(SUITS, 3):
                cards_a.add(Card(three_value, suit))

            for suit in random.sample(SUITS, 2):
                cards_a.add(Card(two_value, suit))

            if three_value == "Ace":
                three_value = "2"
            else:
                three_value = random.choice(values[index:])
                values.remove(three_value)
            two_value = random.choice(values)

            for suit in random.sample(SUITS, 3):
                cards_b.add(Card(three_value, suit))

            for suit in random.sample(SUITS, 2):
                cards_b.add(Card(two_value, suit))

            self.assertTrue(are_cards_bigger(cards_a, cards_b))
Ejemplo n.º 3
0
    def test_bigger_four_of_a_kind(self):
        for i in range(num_tests):
            cards_a = Stack()
            cards_b = Stack()
            values = list(VALUES[1:])
            four_value = random.choice(values)
            index = values.index(four_value)
            values.remove(four_value)
            extra_value = random.choice(values)

            for suit in SUITS:
                cards_a.add(Card(four_value, suit))
            cards_a.add(Card(extra_value, random.choice(SUITS)))

            if four_value == "Ace":
                four_value = "2"
            else:
                four_value = random.choice(values[index:])
                values.remove(four_value)
            extra_value = random.choice(values)

            for suit in SUITS:
                cards_b.add(Card(four_value, suit))
            cards_b.add(Card(extra_value, random.choice(SUITS)))

            self.assertTrue(are_cards_bigger(cards_a, cards_b))
Ejemplo n.º 4
0
    def test_bigger_single(self):
        for i in range(num_tests):
            value = random.choice(VALUES[1:])
            cards_a = Stack(cards=[Card(value, random.choice(SUITS))])

            if value == "Ace":
                value = "2"
            else:
                value = random.choice(VALUES[(VALUES.index(value) + 1):])

            cards_b = Stack(cards=[Card(value, random.choice(SUITS))])

            self.assertTrue(are_cards_bigger(cards_a, cards_b))
Ejemplo n.º 5
0
    def test_bigger_pair(self):
        for i in range(num_tests):
            cards_a = Stack()
            cards_b = Stack()
            value = random.choice(VALUES[1:])

            for suit in random.sample(SUITS, 2):
                cards_a.add(Card(value, suit))

            if value == "Ace":
                value = "2"
            else:
                value = random.choice(VALUES[(VALUES.index(value) + 1):])

            for suit in random.sample(SUITS, 2):
                cards_b.add(Card(value, suit))

            self.assertTrue(are_cards_bigger(cards_a, cards_b))
Ejemplo n.º 6
0
    def test_bigger_straight(self):
        for i in range(num_tests):
            cards_a = Stack()
            cards_b = Stack()
            start_index = random.randint(1, 7)
            cards_a.add([Card(VALUES[start_index], SUITS[0]), Card(VALUES[start_index + 1], SUITS[1])])

            for index in range(start_index + 2, start_index + 5):
                cards_a.add(Card(VALUES[index], random.choice(SUITS)))

            if start_index + 1 == 8:
                start_index = 8
            else:
                start_index = random.randint(start_index + 1, 7)

            cards_b.add([Card(VALUES[start_index], SUITS[0]), Card(VALUES[start_index + 1], SUITS[1])])
            for index in range(start_index + 2, start_index + 5):
                cards_b.add(Card(VALUES[index], random.choice(SUITS)))

            self.assertTrue(are_cards_bigger(cards_a, cards_b))
Ejemplo n.º 7
0
    def test_bigger_straight_flush(self):
        for i in range(num_tests):
            cards_a = Stack()
            cards_b = Stack()
            suit = random.choice(SUITS[:3])
            start_index = random.randint(1, 8)

            for index in range(start_index, start_index + 5):
                cards_a.add(Card(VALUES[index], suit))

            if suit == "Hearts":
                suit = "Spades"
            else:
                suit = random.choice(SUITS[(SUITS.index(suit) + 1):])

            start_index = random.randint(1, 8)
            for index in range(start_index, start_index + 5):
                cards_b.add(Card(VALUES[index], suit))

            self.assertTrue(are_cards_bigger(cards_a, cards_b))
Ejemplo n.º 8
0
def use_selected_cards(bot, player_tele_id, group_tele_id, message_id, job_queue):
    install_lang(player_tele_id)
    valid = True
    bigger = True

    session = scoped_session(session_factory)
    s = session()
    game, player = s.query(Game, Player). \
        filter(Game.group_tele_id == group_tele_id, Player.group_tele_id == group_tele_id,
               Player.player_id == Game.curr_player).first()
    game_round, curr_player, biggest_player, curr_cards, prev_cards = \
        game.game_round, game.curr_player, game.biggest_player, game.curr_cards, game.prev_cards
    player_name, num_cards = player.player_name, player.num_cards

    if curr_cards.size == 0:
        return

    # if get_cards_type(curr_cards) == -1 or (game_round == 1 and not curr_cards.find("3D")) or \
    #         (curr_player != biggest_player and prev_cards.size != 0 and prev_cards.size != curr_cards.size):
    if get_cards_type(curr_cards) == -1 or \
            (curr_player != biggest_player and prev_cards.size != 0 and prev_cards.size != curr_cards.size):
        valid = False

    if valid and curr_player != biggest_player and not are_cards_bigger(prev_cards, curr_cards):
        bigger = False

    if not valid or not bigger:
        session.remove()
        return_cards_to_deck(group_tele_id)

        if not valid:
            message = _("Invalid cards. Please try again\n")
        else:
            message = _("You cards are not bigger than the previous cards. ")
            message += _("Please try again\n")
    else:
        message = _("These cards have been used:\n")
        for card in curr_cards:
            message += suit_unicode(card.suit)
            message += " "
            message += str(card.value)
            message += "\n"
        bot.editMessageText(message, player_tele_id, message_id)

        new_num_cards = num_cards - curr_cards.size
        if new_num_cards == 0:
            finish_game(bot, group_tele_id, player_tele_id, curr_player, player_name, curr_cards, job_queue)
            return

        game.curr_cards = pydealer.Stack()
        game.prev_cards = curr_cards
        player.num_cards = new_num_cards
        s.commit()
        session.remove()
        advance_game(bot, group_tele_id, curr_player, player_name, curr_cards)

    if valid and bigger:
        player_message(bot, group_tele_id, job_queue)
    else:
        player_message(bot, group_tele_id, job_queue, is_edit=True, message_id=message_id)
        bot.send_message(player_tele_id, message)