Beispiel #1
0
 def __init__(self, cardsets, randomizer=False):
     super(Deck, self).__init__()
     if not randomizer:
         randomizer = Randomizer()
     assert (cardsets >= 1)
     self.cardsets = cardsets
     self.randomizer = randomizer
Beispiel #2
0
 def __init__(self,
              players=[],
              randomizer=Randomizer(),
              trumpNumber=CardConstants.NUMBERS[0]):
     super(Round, self).__init__()
     self.players = players
     self.randomizer = randomizer
     self.trumpNumber = trumpNumber
     self.previouslyDeclaredSetByPlayer = {}
Beispiel #3
0
    def __init__(self, players=False, randomizer=False):
        super(Game, self).__init__()
        if not players:
            players = [
            ]  # Do this to get around players=[] resulting in "[]" being a ref that persists call to call (WTF)
        if not randomizer:
            randomizer = Randomizer()

        self.players = players
        self.randomizer = randomizer
Beispiel #4
0
 def test_it_chooses_a_random_start_player(self):
     self.orchestrator.startGame(Randomizer())
     self.orchestrator.registerPlayers()
     self.orchestrator.startRound()
     # Random test, do it a bunch to try and ensure determinism
     for i in range(1, 30):
         self.orchestrator.determineStartPlayer()
         assert self.orchestrator.game.currentRound.firstDrawPlayerIndex >= 0
         assert self.orchestrator.game.currentRound.firstDrawPlayerIndex < len(
             self.orchestrator.game.currentRound.players)
         assert isinstance(
             self.orchestrator.game.currentRound.firstDrawPlayerIndex, int)
Beispiel #5
0
    def __init__(self, cardsets: int, randomizer=Randomizer()):
        """
        Object representing a deck that can contain any multiple of 54 cards
        For each cardset, an individual 54 card deck will be constructed and pushed to the playing deck

        :param cardsets: Number of sets of 54 cards to use
        :param randomizer: Object that shuffles the deck
        """
        super(Deck, self).__init__()
        assert (cardsets >= 1)
        self.cardsets = cardsets
        self.randomizer = randomizer
        self.deck = list()
Beispiel #6
0
    def __init__(self, players=False, randomizer=False, trumpNumber=0):
        super(Round, self).__init__()
        if not players:
            players = []
        if not randomizer:
            randomizer = Randomizer()
        if not trumpNumber:
            trumpNumber = CardConstants.NUMBERS[0]

        self.players = players
        self.randomizer = randomizer
        self.trumpNumber = trumpNumber
        self.previouslyDeclaredSetByPlayer = {}
Beispiel #7
0
    def __init__(self, players=False, randomizer=Randomizer()):
        """
        Game - constructor

        A game has a dictionary of players, which map their peer address to the
        player object. TODO: Is this the best mapping? maybe need to do cookies and
        proper session handling
        :param players: dictionary, defaults to empty dictionary
        :param randomizer:
        """
        super(Game, self).__init__()
        if not players:
            players = [
            ]  # Do this to get around players=[] resulting in "[]" being a ref that persists call to call (WTF)

        self.players = players
        self.randomizer = randomizer
Beispiel #8
0
    def test_it_shuffles_a_deck_randomly(self):
        self.orchestrator.startGame(Randomizer())\
            .registerPlayers()\
            .startRound()\
            .determineStartPlayer()\
            .initializeRoundDeck()\
            .shuffleRoundDeck()

        # TODO: Better way to test non deterministic randomization?
        suitCounts = {}
        deck = self.orchestrator.game.currentRound.deck.deck
        for i in range(0, len(deck)):
            if deck[i].suit not in suitCounts.keys():
                suitCounts[deck[i].suit] = 1
            else:
                suitCounts[deck[i].suit] += 1

        for suit in suitCounts:
            if suit == CardConstants.BIG or suit == CardConstants.SMALL:
                assert suitCounts[suit] == 2
            else:
                assert suitCounts[suit] == 26