def shuffleDeck(self, deck: Deck): """ shuffles deck """ #:: remove all the cards from the deck. cards = deck.popAll() #:: shuffle the list. random.shuffle(cards) #:: put it pack in the deck. deck.extend(cards)
def prepare(self): """ Prepares the Deck of Cards, and splits it evenly among players """ #:: shuffle the playing deck. #:: copy self._current_play_deck = Deck() cards = self._playing_deck.getCards() deck = Deck() deck.extend(cards) self._shuffle_strategy.shuffleDeck(deck) #:: split evenly among players. num_players = len(self._players) next_player = 0 expected_count = (deck.size() // num_players) * num_players count = 0 while (not deck.isEmpty() and count < expected_count): card = deck.popTopCard() self._players[next_player].addToDeckBottom([card]) next_player = (next_player + 1) % num_players count += 1
def main(): #:: for a longer game play(longer because of the number of cards in deck), # uncomment and use this input below # suites = [Suite.HEART, Suite.TILES, Suite.CLOVERS, Suite.PIKES] # ranks = [ # Rank.ACE, Rank.KING, Rank.QUEEN, Rank.JACK, # Rank.TEN, Rank.NINE, Rank.EIGHT, Rank.SEVEN, # Rank.SIX, Rank.FIVE, Rank.FOUR, Rank.THREE, # Rank.TWO # ] # initial_deck = createPlayingDeck(suites, ranks) initial_deck_list = [ Card(Rank.ACE, Suite.HEART), Card(Rank.ACE, Suite.CLOVERS), Card(Rank.ACE, Suite.PIKES), Card(Rank.TWO, Suite.CLOVERS) ] initial_deck = Deck() initial_deck.extend(initial_deck_list) #:: create a list of players. player_one = Player("Mario", Deck()) player_two = Player("Luigi", Deck()) players = [player_one, player_two] #:: create your shuffle strategy shuffleStrategy = SimpleShuffleStrategy() #:: create your ranking strategy rankingStrategy = RankScore() #:: create game game = Game(initial_deck, players, shuffleStrategy, rankingStrategy) #:: call game.start() game.start()