def display_round_str(self, round, terminal=False): for player in self.players: if type(player) != AiPlayer: human = player else: Ai = player human_hand = View(human.cards) if self.community_cards != []: board_hand = View(self.community_cards) print('On the board there is: {}'.format(board_hand)) print('Round: {}. In your hand you have:'.format(round)) print(human_hand) print('ai has {}'.format(Ai.cards)) if not terminal: print('You have £{}, the Ai has £{}.\n'.format(human.money, Ai.money)) player = 0 for action in self.history: acting_player = self.players[player%2] if action != 'd': print('{} chose to {}'.format(acting_player.name, action)) player += 1 else: player = 0 print('') if terminal: prize, winner = self.get_rewards() if prize == 0: print('it was a draw!') else: print("\n{} wins £{}!\n".format(winner.name, prize)) print('You now have £{}, and the Ai has £{}.\n'.format(human.money, Ai.money))
def test_adding_view_to_deck(): """Add a View to an existing Deck""" from terminal_playing_cards import View deck = Deck() view = View([deck.pop() for _ in range(7)]) assert len(view) == 7 assert len(deck) == 45 deck += view assert len(deck) == 52
def show_card_pic(self): if self.value == 11: value = "J" elif self.value == 12: value = "Q" elif self.value == 13: value = "K" elif self.value == 14: value = "A" else: value = self.value card_in_hand = Kartu(str(value), self.suit) hand = View([card_in_hand]) print(hand)
from terminal_playing_cards import View from terminal_playing_cards import Card as Kartu ace_hearts = Kartu("8", "spades", value=1) hand = View([ace_hearts]) print(hand)
def deal(self): """Deal cards for a blackjack round. Hide the Dealer's second card""" for role in self.players + [self.dealer]: role.hand = View([self.deck.pop() for _ in range(2)]) self.dealer.hand[1].hidden = True
def test_hand_can_be_set_after_role_creation(queen_spades): from terminal_playing_cards import View role = Role() role.hand = View([queen_spades, queen_spades]) assert role.total == 20
def ace_hand(): from terminal_playing_cards import View, Card return View([Card("A", "hearts", value=1), Card("K", "hearts", value=10)])