def shuffle(self): """ Shuffling hands during initializing class instance. Marking last cards in hands. :return: None """ shuffle_deck = self.deck random.shuffle(shuffle_deck) self.north = [ Card(symbol) for symbol in sorted(shuffle_deck[:13], key=lambda x: (x[0], -int(x[1:]))) ] self.south = [ Card(symbol) for symbol in sorted(shuffle_deck[13:26], key=lambda x: (x[0], -int(x[1:]))) ] self.west = [ Card(symbol) for symbol in sorted(shuffle_deck[26:39], key=lambda x: (x[0], -int(x[1:]))) ] self.east = [ Card(symbol) for symbol in sorted(shuffle_deck[39:52], key=lambda x: (x[0], -int(x[1:]))) ] self.north[-1].last_card = True self.south[-1].last_card = True self.west[-1].last_card = True self.east[-1].last_card = True
def test_loose_money(self): chloe = Player("Chloe", 0) board = Board() card = Card(card_id="666", name="", card_type="loose-money", value=100) card.execute(chloe, None, board) self.assertEqual(INITIAL_MONEY - 100, chloe.money) self.assertEqual(board.park_money, 100)
def test_sorts_cards(self): two_of_spades = Card(rank="2", suit="Spades") five_of_diamonds = Card(rank="5", suit="Diamonds") five_of_hearts = Card(rank="5", suit="Hearts") eight_of_hearts = Card(rank="8", suit="Hearts") ace_of_clubs = Card(rank="Ace", suit="Clubs") unsorted_cards = [ five_of_hearts, five_of_diamonds, two_of_spades, ace_of_clubs, eight_of_hearts ] unsorted_cards.sort() self.assertEqual( unsorted_cards, [ two_of_spades, five_of_diamonds, five_of_hearts, eight_of_hearts, ace_of_clubs ] )
def start_game(self, blind): self._main = [Card(), Card()] self._money -= blind self._mise = blind self.play = True self.flop = 0 self.cartes_flop = list() self.est_tapis = False
def __init__(self, obj): Card.__init__(self, obj) # self.flavorText = obj['flavorText'] self.manaCost = obj['manaCost'] self.convertedManaCost = obj['convertedManaCost'] self.power = None self.toughness = None self.summoningSickness = True
def test_go_to_jai(self): chloe = Player("Chloe", 0) board = Board() board.boxes[3].players.append(0) chloe.position = 3 card = Card(card_id="666", name="", card_type="go-to-jail", value=-1) card.execute(chloe, None, board) self.assertTrue(chloe.in_jail) self.assertEqual(JAIL_POSITION, chloe.position)
def test_does_not_deem_two_consecutive_cards_as_straight(self): cards = [ Card(rank="6", suit="Hearts"), Card(rank="7", suit="Diamonds") ] validator = StraightValidator(cards=cards) self.assertEqual(validator.is_valid(), False)
def test_card_can_evaluate_its_rank_with_another_one(self): queen_of_spades = Card(rank="Queen", suit="Spades") king_of_spades = Card(rank="King", suit="Spades") evaluation = queen_of_spades < king_of_spades self.assertEqual( evaluation, True, "The sort algorithm is not sorting the lower card first" )
def use_card(self, card: Card): for c in self._hand: # matching card type if c.card_id() == card.card_id(): self._hand.remove(c) self.modify_mana(-card.cost()) if self._currentMana < 0: raise InsufficientManaException(card) self.modify_health(card.my_health_change()) self._nextTurnDraw += card.card_draw()
def setUp(self): five = Card(rank="5", suit="Clubs") self.king_of_clubs = Card(rank="King", suit="Clubs") self.king_of_diamonds = Card(rank="King", suit="Diamonds") self.king_of_hearts = Card(rank="King", suit="Hearts") ace = Card(rank="Ace", suit="Spades") self.cards = [ five, self.king_of_clubs, self.king_of_diamonds, self.king_of_hearts, ace ]
def test_removes_specified_number_of_cards_from_deck(self): ace = Card(rank="Ace", suit="Spades"), eight = Card(rank="8", suit="Diamonds") cards = [ace, eight] deck = Deck() deck.add_cards(cards) self.assertEqual(deck.remove_cards(1), [ace]) self.assertEqual(deck.cards, [eight])
def setUp(self): self.five_of_clubs = Card(rank="5", suit="Clubs") self.king_of_diamonds = Card(rank="King", suit="Diamonds") self.king_of_hearts = Card(rank="King", suit="Hearts") self.ace_of_clubs = Card(rank="Ace", suit="Clubs") self.ace_of_spades = Card(rank="Ace", suit="Spades") self.cards = [ self.five_of_clubs, self.king_of_diamonds, self.king_of_hearts, self.ace_of_clubs, self.ace_of_spades ]
def test_validates_that_cards_have_a_high_card(self): cards = [ Card(rank="7", suit="Clubs"), Card(rank="Ace", suit="Diamonds") ] validator = HighCardValidator(cards=cards) self.assertEqual( validator.is_valid(), True )
def test_birthday(self): game = Game({0: "Chloe", 1: "Lucien", 2: "Gildas", 3: "Emile"}) chloe = game.players[0] lucien = game.players[1] gildas = game.players[2] emile = game.players[3] card = Card(card_id="666", name="", card_type="birthday", value=50) card.execute(chloe, game.players, game.board) self.assertEqual(INITIAL_MONEY + 3 * 50, chloe.money) self.assertEqual(INITIAL_MONEY - 50, lucien.money) self.assertEqual(INITIAL_MONEY - 50, gildas.money) self.assertEqual(INITIAL_MONEY - 50, emile.money)
def test_validates_that_cards_have_exactly_one_pair(self): cards = [ Card(rank = "Ace", suit = "Spades"), Card(rank = "Ace", suit = "Clubs") ] validator = PairValidator(cards = cards) self.assertEqual( validator.is_valid(), True )
def test_passes_new_cards_to_hand(self): mock_hand = MagicMock() player = Player(name="Sue", hand=mock_hand) cards = [ Card(rank="Ace", suit="Spades"), Card(rank="Queen", suit="Diamonds") ] player.add_cards(cards) mock_hand.add_cards.assert_called_once_with(cards)
def test_shows_all_its_cards_in_technical_representation(self): cards = [ Card(rank = "Ace", suit = "Diamonds"), Card(rank = "7", suit = "Clubs") ] hand = Hand() hand.add_cards(cards) self.assertEqual( repr(hand), "7 of Clubs, Ace of Diamonds" )
def test_shuffles_cards_in_random_order(self, mock_shuffle): deck = Deck() cards = [ Card(rank="Ace", suit="Spades"), Card(rank="8", suit="Diamonds") ] deck.add_cards(cards) deck.shuffle() mock_shuffle.assert_called_once_with(cards)
def test_interacts_with_validator_to_get_winning_hand(self): class HandWithOneValidator(Hand): VALIDATORS = (PairValidator,) ace_of_hearts = Card(rank="Ace", suit="Hearts") ace_of_spades = Card(rank="Ace", suit="Spades") cards = [ace_of_hearts, ace_of_spades] hand = HandWithOneValidator() hand.add_cards(cards=cards) self.assertEqual( hand.best_rank(), (0, "Pair", cards) )
def deal(self, seed, red, blue, bystander, assassin): random.seed(seed) artwork = [] for i in range(0, self.NUM_ARTWORK): artwork += [i] teams = [] for i in range(0, red): teams += ["red"] for i in range(0, blue): teams += ["blue"] for i in range(0, bystander): teams += ["bystander"] for i in range(0, assassin): teams += ["assassin"] while len(teams) < 20: teams += ["bystander"] self.cards = [] for x in range(5): self.cards += [[]] for y in range(4): index = random.randrange(0, len(artwork)) artwork_selection = artwork[index] del artwork[index] index = random.randrange(0, len(teams)) team_selection = teams[index] del teams[index] self.cards[x] += [ Card(artwork_selection, team_selection, False) ] self.notify_listeners(OverwriteCardsEvent(self.cards))
def standard_deck(include_rainbow=True): deck = [] id = 0 for color in Card.COLORS: if not include_rainbow and color == Card.RAINBOW: continue for number in range(1, Card.NUM_NUMBERS + 1): if color == Card.RAINBOW: quantity = 1 elif number == 1: quantity = 3 elif 2 <= number <= 4: quantity = 2 elif number == 5: quantity = 1 else: raise Exception("Unknown card parameters.") for i in range(quantity): deck.append(Card(id, color, number)) id += 1 if include_rainbow: assert len(deck) == 55 else: assert len(deck) == 50 return deck
def __init__(self): self.full_deck = [] for card_suit in Suit: for i in range(1, Deck.__amount_of_cards_of_one_suit + 1): self.full_deck.append( Card(card_suit, i, i >= 10, self.__get_card_value(i)))
def create_deck(self) -> list: deck = [] for card_id in list([1, 10, 9, 13, 2, 5]): deck.append(Card(card_id, self.value_str)) return deck[:]
def __init__(self): """ A deck is constructed as a list of all 52 unique card combinations of suit and rank """ self.card_deck = [] for suit in Card.suits: for rank in Card.rankings: self.card_deck.append(Card(rank, suit))
def load_deck_description(self, deck_description): """ Load the initial deck from string. """ self.deck = [] for card in deck_description.split(","): number, color, id = card.split() self.deck.append(Card(id=int(id), color=color, number=int(number)))
def create_deck(self) -> list: deck = [] for card_id in range(1, 52): deck.append(Card(card_id, self.value_str)) shuffle(deck) return deck[:]
def test_returns_high_card_from_card_collection(self): ace_of_diamonds = Card(rank="Ace", suit="Diamonds") cards = [ Card(rank="5", suit="Spades"), Card(rank="8", suit="Diamonds"), Card(rank="10", suit="Clubs"), Card(rank="Queen", suit="Spades"), ace_of_diamonds ] validator = HighCardValidator(cards=cards) self.assertEqual( validator.valid_cards(), [ace_of_diamonds] )
def test_returns_pair_from_card_collection(self): ten_of_spades = Card(rank = "10", suit = "Spades") ten_of_clubs = Card(rank = "10", suit = "Clubs") cards = [ Card(rank = "3", suit = "Hearts"), Card(rank = "5", suit = "Diamonds"), ten_of_clubs, ten_of_spades, Card(rank = "King", suit = "Clubs") ] validator = PairValidator(cards = cards) self.assertEqual( validator.valid_cards(), [ten_of_clubs, ten_of_spades] )
def test_taxes(self): chloe = Player("Chloe", 0) board = Board() chloe.buy_good(board.boxes[1]) chloe.buy_good(board.boxes[3]) chloe.buy_good(board.boxes[6]) chloe.buy_good(board.boxes[8]) chloe.buy_good(board.boxes[9]) chloe.buy_houses(board.boxes[1], 5) chloe.buy_houses(board.boxes[3], 3) chloe.buy_houses(board.boxes[6], 5) chloe.buy_houses(board.boxes[8], 2) money_before_taxes = chloe.money card = Card(card_id="666", name="", card_type="taxes", value=[20, 50]) card.execute(chloe, None, board) tax = 5 * 20 + 2 * 50 self.assertEqual(money_before_taxes - tax, chloe.money) self.assertEqual(board.park_money, tax)
def make_cards(cards_filename): with open(cards_filename) as cards_file: json_cards = json.loads(cards_file.read()) cards = {} for card in json_cards: card_id = int(card) cards[card_id] = Card(card_id, json_cards[card]["name"], json_cards[card]["type"], json_cards[card]["value"]) return cards