예제 #1
0
파일: Shuffle.py 프로젝트: jidemusty/war
 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)
예제 #2
0
파일: Game.py 프로젝트: jidemusty/war
    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
예제 #3
0
파일: main.py 프로젝트: jidemusty/war
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()