def draw(self): ''' Draws a card from the top of the deck and adds it to player's hand. :raises BlackjackException: if player is standing, won or lost the hand ''' if self.is_standing(): raise BlackjackException("{0} is standing.".format(self.name)) if self.is_loser(): raise BlackjackException("{0} lost.".format(self.name)) self.hand.draw()
def hit(self): ''' Draws a card for the first player. :raises BlackjackException: if game came to a conclusion or if it's not player's turn ''' if self.is_end(): raise BlackjackException("Game ended.") if self.dealer_turn: raise BlackjackException("Not player\'s turn.") self.player.draw()
def stand(self): ''' Stands the hand and cedes the turn to another player. :raises BlackjackException: if player is standing, won or lost the hand ''' if self.is_standing(): raise BlackjackException("{0} is already standing.".format( self.name)) if self.is_loser(): raise BlackjackException("{0} lost.".format(self.name)) self.standing = True
def deal(self): ''' Lets the dealer to take a decision to play. :raises BlackjackException: if game came to a conclusion or if it's not dealer's turn ''' if self.is_end(): raise BlackjackException("Game ended.") if not self.dealer_turn: raise BlackjackException("Not dealer\'s turn.") move = self.dealer.proceed() return move
def stand(self): ''' Stands first player's turn and passes the turn to the dealer. :raises BlackjackException: if game came to a conclusion or if it's not player's turn, if player's already standing ''' if self.is_end(): raise BlackjackException("Game ended.") if self.dealer_turn: raise BlackjackException("You\'re already standing.") self.player.stand() self.dealer_turn = True
def draw(self): ''' Draws a card from the stack. :return: Card - the card from the top of the stack is popped :raises BlackjackException: if all cards have been popped and no cards are left in the stack ''' if len(self.stack) == 0: raise BlackjackException("No cards left.") return self.stack.pop()
def proceed(self): ''' Performs the next move of the autoplayer. :return: string - name of autoplayer's move :raises BlackjackException: if the personality does not returns a valid move ''' move = self.personality.think() if move == "hit": self.draw() elif move == "stand": self.stand() else: raise BlackjackException("Invalid move.") return move