Beispiel #1
0
 def test_to_dict(self):
     ann_card: Card = Card("10", "C")
     betsy_card: Card = Card("K", "C")
     caroline_card: Card = Card("3", "C")
     diane_card: Card = Card("2", "S")
     moves: List[Move] = [
         Move(Player("Ann", [ann_card]), ann_card),
         Move(Player("Betsy", [betsy_card]), betsy_card),
         Move(Player("Caroline", [caroline_card]), caroline_card),
         Move(Player("Diane", [diane_card]), diane_card),
     ]
     t: Trick = Trick(moves)
     self.assertEqual(
         t.to_dict(),
         {
             "moves": [
                 {
                     "player": {
                         "name": "Ann",
                         "cards": [{"value": "10", "int": 10, "suit": "C"}],
                     },
                     "card": {"value": "10", "int": 10, "suit": "C"},
                 },
                 {
                     "player": {
                         "name": "Betsy",
                         "cards": [{"value": "K", "int": 13, "suit": "C"}],
                     },
                     "card": {"value": "K", "int": 13, "suit": "C"},
                 },
                 {
                     "player": {
                         "name": "Caroline",
                         "cards": [{"value": "3", "int": 3, "suit": "C"}],
                     },
                     "card": {"value": "3", "int": 3, "suit": "C"},
                 },
                 {
                     "player": {
                         "name": "Diane",
                         "cards": [{"value": "2", "int": 2, "suit": "S"}],
                     },
                     "card": {"value": "2", "int": 2, "suit": "S"},
                 },
             ]
         },
     )
 def __init__(self):
     self.cards = list()
     #loop over 4 suits
     for i in range(4):
         #loop over 13 cards for each suit
         for j in range(13):
             #add a card of each value from each suit
             self.cards.append(Card(i, j))
 def test_create_card(self):
     book = 'the golden bough'
     with open('../data/source/the golden bough.txt', 'r') as reader:
         for line in reader.readlines():
             text = line.strip('\n')
             card = Card()
             card.book = book
             card.word = text.lower()
Beispiel #4
0
 def _create_deck(self, num_decks):
     print("############ CREATING DECK ##########")
     decks = []
     for deck in range(0, num_decks):
         for suit in self._SUITS:
             for card in self._CARDS:
                 decks.append(Card(card, suit))
     return decks
Beispiel #5
0
 def test_AllValidCardsAreAccepted(self):
     values = [
         '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'
     ]
     colours = ['C', 'D', 'H', 'S']
     for v in values:
         for c in colours:
             Card(v + c)
 def test_card_creation_hidden(self):
     cardVal = 11
     cardFace = 'A'
     cardAce = True
     cardHidden = True
     testCard = Card(value=cardVal, face=cardFace, ace=cardAce)
     testCard.__is_hidden__ = cardHidden
     self.assertTrue(testCard.__is_hidden__)
    def test_card_is_ace(self):
        cardVal = 11
        cardFace = 'A'
        cardAce = True
        cardHidden = False
        testCard = Card(value=cardVal, face=cardFace, ace=cardAce)

        self.assertEqual(testCard.is_ace(), cardAce)
    def test_card_value(self):
        cardVal = 9
        cardFace = str(9)
        cardAce = False
        cardHidden = True
        testCard = Card(value=cardVal, face=cardFace, ace=cardAce)

        self.assertEqual(testCard.getValue(), cardVal)
Beispiel #9
0
 def test_to_dict(self):
     p: Player = Player(
         "Bobby Fisher",
         [
             Card("10", "S"),
             Card("2", "H"),
             Card("10", "D"),
             Card("J", "D"),
             Card("A", "S"),
         ],
     )
     self.assertEqual(
         p.to_dict(),
         {
             "name":
             "Bobby Fisher",
             "cards": [
                 {
                     "value": "10",
                     "int": 10,
                     "suit": "S"
                 },
                 {
                     "value": "A",
                     "int": 14,
                     "suit": "S"
                 },
                 {
                     "value": "2",
                     "int": 2,
                     "suit": "H"
                 },
                 {
                     "value": "10",
                     "int": 10,
                     "suit": "D"
                 },
                 {
                     "value": "J",
                     "int": 11,
                     "suit": "D"
                 },
             ],
         },
     )
    def test_is_hidden_when_not_hidden(self):
        cardVal = 11
        cardFace = 'A'
        cardAce = True
        cardHidden = False
        testCard = Card(value=cardVal, face=cardFace, ace=cardAce)
        testCard.__is_hidden__ = cardHidden

        self.assertFalse(testCard.is_hidden())
Beispiel #11
0
    def load_deck(self):
        with open('src/cards.json', 'r') as json_file:
            data = json.load(json_file)
            for card_json in data['cards']:
                card = Card(card_json['name'], card_json['colour'],
                            card_json['value'])
                self._deck.append(card)
        self._AI.load_possible_cards(self._deck)

        self.full_deck += self._deck
 def get_non_books(self):
     '''Get a list of values that are not currently in closed books'''
     #list of ints 0-12
     all_cards = list(range(13))
     #remove any values that player 1 has on the table
     remove_player_one = self.remove_values(all_cards, self.player1.books)
     #remove any values that player 2 has on the table
     remove_player_two = self.remove_values(remove_player_one,
                                            self.player2.books)
     #return a list of cards for the remaining numbers (we don't care about suits)
     return list(map(lambda val: Card(0, val), remove_player_two))
Beispiel #13
0
    def test_get_card(self):
        card = Card("card1", 1, "w")
        token = Token(1, 1, card)
        token.set_card(card)
        self.assertEqual(card, token.get_card())
    


    

        
    def test_unhide_when_hidden(self):
        cardVal = 11
        cardFace = 'A'
        cardAce = True
        cardHidden = True
        testCard = Card(value=cardVal, face=cardFace, ace=cardAce)
        testCard.__is_hidden__ = cardHidden

        testCard.unhide()

        self.assertFalse(testCard.__is_hidden__)
Beispiel #15
0
    def __init__(self):
        """
    Pack ctor.
    """

        cards = []
        for _ in range(6):
            for suit in Card.SUITS:
                for pip in Card.PIPS:
                    cards.append(Card(suit, pip))

        self.__cards = cards
Beispiel #16
0
def test_no_combinations(checker):
    hand = [Card(1, 'Hearts'), Card(10, 'Diamonds')]
    cards = [
        Card(12, 'Hearts'),
        Card(5, 'Clubs'),
        Card(7, 'Spades'),
        Card(14, 'Diamonds'),
        Card(6, "Hearts")
    ]
    assert checker.find_combination(hand, cards) is None
Beispiel #17
0
 def test_get_cards(self):
     p: Player = Player(
         "Bobby Fisher",
         [
             Card("10", "S"),
             Card("2", "H"),
             Card("10", "D"),
             Card("J", "D"),
             Card("A", "S"),
         ],
     )
     self.assertEqual(
         p.get_cards(),
         [
             Card("10", "S"),
             Card("A", "S"),
             Card("2", "H"),
             Card("10", "D"),
             Card("J", "D"),
         ],
     )
Beispiel #18
0
def test_full_house_pair_highest(checker):
    hand = [Card(14, 'Diamonds'), Card(13, 'Spades')]
    cards = [
        Card(14, 'Hearts'),
        Card(13, "Clubs"),
        Card(13, 'Diamonds'),
        Card(9, 'Clubs'),
        Card(9, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == (6, 14, 13)
Beispiel #19
0
def test_is_straight_start_from_ace(checker):
    hand = [Card(14, 'Spades'), Card(9, 'Spades')]
    cards = [
        Card(2, 'Hearts'),
        Card(3, "Diamonds"),
        Card(4, 'Diamonds'),
        Card(5, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == (4, 5)
Beispiel #20
0
def test_is_three(checker):
    hand = [Card(4, 'Spades'), Card(10, 'Spades')]
    cards = [
        Card(10, 'Hearts'),
        Card(10, "Diamonds"),
        Card(2, 'Diamonds'),
        Card(3, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == (3, 10)
Beispiel #21
0
def test_is_straight(checker):
    hand = [Card(5, 'Spades'), Card(6, 'Spades')]
    cards = [
        Card(4, 'Hearts'),
        Card(7, "Diamonds"),
        Card(3, 'Spades'),
        Card(3, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == (4, 7)
Beispiel #22
0
def test_is_straight_flush(checker):
    hand = [Card(5, 'Hearts'), Card(6, 'Hearts')]
    cards = [
        Card(4, 'Hearts'),
        Card(7, "Hearts"),
        Card(3, 'Hearts'),
        Card(8, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == (8, 7)
Beispiel #23
0
def test_is_flush_royal(checker):
    hand = [Card(14, 'Hearts'), Card(13, 'Hearts')]
    cards = [
        Card(12, 'Hearts'),
        Card(11, "Hearts"),
        Card(10, 'Hearts'),
        Card(8, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == 9
Beispiel #24
0
def test_is_straight_flush_start_from_ace(checker):
    hand = [Card(3, 'Hearts'), Card(4, 'Hearts')]
    cards = [
        Card(2, 'Hearts'),
        Card(14, "Hearts"),
        Card(5, 'Hearts'),
        Card(8, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == (8, 5)
Beispiel #25
0
def test_is_straight_flush_with_four_cards(checker):
    hand = [Card(3, 'Hearts'), Card(4, 'Hearts')]
    cards = [
        Card(2, 'Hearts'),
        Card(13, "Clubs"),
        Card(1, 'Hearts'),
        Card(8, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) is None
Beispiel #26
0
def test_is_two_pair(checker):
    hand = [Card(2, 'Spades'), Card(6, 'Spades')]
    cards = [
        Card(10, 'Hearts'),
        Card(10, "Diamonds"),
        Card(2, 'Diamonds'),
        Card(6, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == [2, 10, 6]
Beispiel #27
0
def test_is_full_house(checker):
    hand = [Card(2, 'Diamons'), Card(9, 'Spades')]
    cards = [
        Card(2, 'Spades'),
        Card(9, "Hearts"),
        Card(9, 'Clubs'),
        Card(1, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == (6, 2, 9)
Beispiel #28
0
def test_is_flush(checker):
    hand = [Card(14, 'Spades'), Card(9, 'Spades')]
    cards = [
        Card(2, 'Spades'),
        Card(3, "Spades"),
        Card(4, 'Spades'),
        Card(1, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) == (5, 'Spades')
Beispiel #29
0
def test_is_straight_with_four_cards(checker):
    hand = [Card(13, 'Spades'), Card(9, 'Spades')]
    cards = [
        Card(2, 'Hearts'),
        Card(3, "Diamonds"),
        Card(5, 'Diamonds'),
        Card(1, 'Diamonds')
    ]
    assert checker.find_combination(hand, cards) is None
Beispiel #30
0
def load_word_list():
    srcdir = '../data/source'
    files = [f for f in listdir(srcdir) if isfile(join(srcdir, f))]
    cards = {}
    for file in files:
        bookname = splitext(file)[0]
        with open(join(srcdir, file), 'r') as reader:
            for line in reader.readlines():
                text = line.strip('\n')
                card = Card()
                card.book = bookname
                card.word = text.lower()
                cards[card.word] = card
    cardbox = CardBox()
    cardbox.cards = cards