Esempio n. 1
0
    def deal(self, player):
        """
        New game is started in given session.
        The game can only be started by dealer.
        Dealer deals the cards.
        The turn is given to player after dealer.

        Fails if:
            - Current game have not been finished.
            - Session is not full.
            - Current user is not a dealer.
        """

        if not self.state in ('ready', 'endGame'):
            raise GameError('Current game have not been finished or session is not full.')
        if player != self.dealer:
            raise GameError('Only the dealer can start the game.')

        cards = ThousandCard.generateDeck()
        shuffle(cards)
        for i, player in enumerate([self.player_1, self.player_2, self.player_3]):
            player.cards = cards[i*7:(i+1)*7]
            player.passed = False
            player.bet = None
            player.blind = None
            player.bank = []
            player.thrown = []
            player.tricks = []
            player.calls = ''
            player.put()
        self.info = '%s deals the cards' % player.user.nickname()
        self.bank = cards[21:24]
        self.memo = []
        self.turn = self.dealer = self.getNextPlayer(self.dealer)
        self.bet = 90
        self.state = 'bettings'
        self.blind = False
        self.trump = None
        self.info = None
        self.put()
Esempio n. 2
0
 def test_points(self):
     deck = ThousandCard.generateDeck()
     for c in deck:
         self.assertEqual(c.points(), self.points[c.value()])
     self.assertEqual(sum([c.points() for c in deck]), 120)