示例#1
0
    def test_one_winner_with_one_multiple_same_value_card(self):
        #init player 1
        cards_player1 = []
        cards_player1.append(Card(0, 1))
        cards_player1.append(Card(3, 10))
        hand_player1 = Hand(cards_player1)
        player1 = Player("Player 1", hand_player1)

        # init player 2
        cards_player2 = []
        cards_player2.append(Card(2, 9))
        cards_player2.append(Card(1, 8))
        hand_player2 = Hand(cards_player2)
        player2 = Player("Player 2", hand_player2)

        #init Table
        cards_table = []
        cards_table.append(Card(0, 3))
        cards_table.append(Card(1, 8))
        cards_table.append(Card(2, 4))
        cards_table.append(Card(0, 7))
        cards_table.append(Card(0, 2))

        players = []
        players.append(player1)
        players.append(player2)

        pack = Pack()

        table = Table(players, pack)
        table.set_cards(cards_table)

        expected_winner = []
        expected_winner.append(player2)
        self.assertEqual(expected_winner, get_winners(players, table))
示例#2
0
    def _cardInfoListCallback(self, context, cardInfo, eol, userData):
        if cardInfo:
            card = Card(cardInfo.contents)
            self.cards.insert(card.index, card)

            for ev in self.events['cardInfoList']:
                ev(userData)
def get_card(number_card):
    logger = logger_config.get_logger()
    user_card = f'{number_card[:4]}*****{number_card[-4:]}'
    base_card = Card().find_card({"card": user_card})

    if not base_card:
        code, json_payload = format_error_response(400, 'Bad Request​',
                                                   f'Card Not Found')
        return code, json_payload

    if not verify_password(base_card['hash_card'], number_card):
        code, json_payload = format_error_response(400, 'Bad Request​',
                                                   'number card invalid')
        return code, json_payload
    if not base_card:
        code, json_payload = format_error_response(400, 'Bad Request​',
                                                   f'Card Not Found')
        return code, json_payload
    data = {"id": str(base_card['_id']), "card": user_card}
    code, json_payload = format_success_response(200, data)
    logger.info('Card - Get card successfully')
    return code, json_payload
def post_card(request):
    logger = logger_config.get_logger()
    payload = request.get_json()
    if not payload:
        code, json_payload = format_error_response(400, 'Bad Request​',
                                                   'No payload.')
        return code, json_payload
    fields_required = ["card"]

    for fields in fields_required:
        if not payload.get(fields):
            code, json_payload = format_error_response(
                400, 'Bad Request​', f'field {fields} is required')
            return code, json_payload

    if len(payload['card']) <= int(os.getenv('DIGITS')):
        code, json_payload = format_error_response(
            400, 'Bad Request​',
            f'nnumber must be greater than {os.getenv("DIGITS")} characters')
        return code, json_payload
    if not payload['card'].isdigit():
        code, json_payload = format_error_response(400, 'Bad Request​',
                                                   'Only caracter number')
        return code, json_payload

    payload['hash_card'] = generate_password_hash(payload['card'])
    numbers_card = payload['card']
    payload['card'] = f'{numbers_card[:4]}*****{numbers_card[-4:]}'
    try:
        logger.info('Card - card successfully registered ')
        id = Card().insert_card(payload)
        data = {"id": str(id)}
        code, json_payload = format_success_response(201, data)

        return code, json_payload
    except Exception as error:
        logger.error('Card - Error register card ')
        return 500, error
示例#5
0
 def __init__(self):
     self.all_cards = []
     for suit in suits:
         for rank in ranks:
             self.all_cards.append(Card(suit, rank))
示例#6
0
 def __init__(self):
     self.cards = []
     for suit in CardSuit:
         for val in range(2, 15):
             self.cards.append(Card(val, suit))
             random.shuffle(self.cards)
示例#7
0
    def draw(self):
        currentSuit = self.cards[self.currentCardIndex] // 13
        currentNumber = self.cards[self.currentCardIndex] % 13
        self.currentCardIndex += 1

        return Card(currentSuit, currentNumber)