def test_status_bust():
    player = Player()
    player.add_card(Card(10))
    player.add_card(Card(10))
    player.add_card(Card(2))
    assert player.total == 22
    assert player.status == Statuses["BUST"]
 def test_two_aces(self):
     player = Player()
     player.add_card(Card(1))
     player.add_card(Card(1))
     assert player.total == 12
     player.add_card(Card(9))
     assert player.status == Statuses["PLAYING"]
예제 #3
0
    def _parseCard(self, r, cursor):
        # Assosiate list items to readable variables.
        (name, manacost, cmc, type, supertypes, subtypes, rarity, text, flavor,
         power, toughness, loyalty, rulings, watermark, printings, setname,
         blockname, names) = r

        printings = self._searchSetsForPrintings(printings, cursor)
        mtgCard = Card(name, manacost, cmc, type, supertypes, subtypes, rarity,
                       text, flavor, power, toughness, loyalty, rulings,
                       watermark, printings, setname, blockname)

        # Check for transformation and other related cards
        if names is not None and names != "":
            temp = names.split("|")  # Split the names of the card.
            frontName = temp[0]
            backName = temp[1]

            if backName.lower() == mtgCard.cardName.lower():
                mtgCard.frontFacing = False

            if len(temp) == 2:
                mtgCard = self._getTransformation(mtgCard, frontName, backName,
                                                  cursor)
            else:
                if mtgCard.frontFacing:
                    mtgCard.relatedCards.append(temp[2])
                    mtgCard = self._getTransformation(mtgCard, frontName,
                                                      backName, cursor)
                else:
                    del temp[temp.index(mtgCard.cardName)]
                    mtgCard.relatedCards.extend(temp)

        return mtgCard
def test_status_blackjack():
    player = Player()
    assert player.total == 0
    assert player.status == Statuses["PLAYING"]
    player.add_card(Card(1))
    player.add_card(Card(10))
    assert player.total == 21
    assert player.status == Statuses["BLACKJACK"]
 def test_add_ace(self):
     player = Player()
     player.add_card(Card(4))
     player.add_card(Card(10))
     player.add_card(Card(1))
     assert player.total == 15
     assert player.status == Statuses["PLAYING"]
     player.add_card(Card(10))
     assert player.total == 25
     assert player.status == Statuses["BUST"]
 def test_two_aces_no_bust(self):
     player = Player()
     player.add_card(Card(1))
     player.add_card(Card(1))
     assert player.total == 12
     player.add_card(Card(8))
     assert player.total == 20
     player.add_card(Card(2))
     assert player.total == 12
     assert player.status == Statuses["PLAYING"]
def test_status_playing():
    player = Player()
    assert player.total == 0
    assert player.status == Statuses["PLAYING"]
    player.add_card(Card(13))
    player.add_card(Card(10))
    assert player.total == 20
    assert player.status == Statuses["PLAYING"]
    player.add_card(Card(1))
    assert player.total == 21
    assert player.status == Statuses["PLAYING"]
def test_Card_toJSON():
    json = Card(5).toJSON()
    print(json)
    assert json["num"] == 5
    assert json["face"] == 5
    assert json["value"] == 5
    assert "suit" in json
def test_card_validation():
    with pytest.raises(Exception, match="Cards must be a list of type Card"):
        Player(cards=[1])
    with pytest.raises(Exception, match="Cards must be a list of type Card"):
        cards = index.serialize_cards(make_cards([1, 2]))
        Player(cards=cards)
    with pytest.raises(Exception, match="Cards must be a list of type Card"):
        Player(cards=Card(1))
예제 #10
0
    def _searchForTransformation(self, card, frontName, backName, cursor):
        cardBack = None
        sql = (
            "SELECT cardName, cardManaCost, cardCmc, cardType, cardSupertypes, cardSubtypes, cardRarity, cardText, cardFlavor, cardPower, "
            "cardToughness, cardLoyalty, cardRulings, cardWatermark, cardPrintings, setName, blockName, cardNames FROM mtgCard NATURAL JOIN mtgSet "
            "WHERE cardName LIKE ? GROUP BY cardName;")
        nameToSearchBy = None

        # Check if we are looking at the back of the card, if so we need to search for the front.
        if card.frontFacing == False:
            nameToSearchBy = frontName
        else:
            nameToSearchBy = backName

        cursor.execute(sql, (nameToSearchBy, ))
        r = cursor.fetchone()

        if r is not None:
            # Assosiate list items to readable variables.
            (name, manacost, cmc, type, supertypes, subtypes, rarity, text,
             flavor, power, toughness, loyalty, rulings, watermark, printings,
             setname, blockname, names) = r

            printings = self._searchSetsForPrintings(printings, cursor)
            cardBack = Card(name,
                            manacost,
                            cmc,
                            type,
                            supertypes,
                            subtypes,
                            rarity,
                            text,
                            flavor,
                            power,
                            toughness,
                            loyalty,
                            rulings,
                            watermark,
                            printings,
                            setname,
                            blockname,
                            card,
                            frontFacing=False)

        return cardBack
예제 #11
0
def deserialize_cards(cards):
    return [Card(c["num"]) for c in cards]
 def test_six(self):
     player = Player()
     player.add_card(Card(1))
     player.add_card(Card(5))
     assert player.total == 16
 def test_one_ace(self):
     player = Player()
     player.add_card(Card(10))
     player.add_card(Card(1))
     assert player.total == 21
     assert player.status == Statuses["BLACKJACK"]