def test_dealer_give_me_x2_bet_prize_if_players_hand_win(self): player = PlayerBuilder().withChips(100).withBet(100).withHand(HandBuilder().withWin().create()).create() dealer = Dealer() dealer.settleGame(player) self.assertEqual(player.chips, 200)
def teste_vitoria_dealer_com_soma_maior_que_jogador(): dealer = Dealer() jogador = Jogador('teste') jogador.receber_cartas([Carta('10', ''), Carta('9', '')]) dealer.receber_cartas([Carta('Q', ''), Carta('J', '')]) assert dealer.resultado_jogador(jogador) == -1
def test_dealer_take_100_from_player_dollars(self): player = PlayerBuilder().withCash(100).create() dealer = Dealer() dealer.buyChips(player, 100) self.assertEqual(player.cash, 0)
def teste_empate(): dealer = Dealer() jogador = Jogador('teste') jogador.receber_cartas([Carta('A', ''), Carta('10', '')]) dealer.receber_cartas([Carta('J', ''), Carta('A', '')]) assert dealer.resultado_jogador(jogador) == 0
class DealerTests(unittest.TestCase): def setUp(self): self.dealer = Dealer() def test_build_deck_has_52_cards(self): deck = Dealer.build_deck() self.assertEquals(52, len(deck)) def test_can_hit_with_hand_value_lte_16(self): self.dealer.add_card(Card(u'K♠')) self.dealer.add_card(Card(u'6♠')) self.assertTrue(self.dealer.can_hit()) def test_can_hit_with_hand_value_gt_16(self): self.dealer.add_card(Card(u'K♠')) self.dealer.add_card(Card(u'7♠')) self.assertFalse(self.dealer.can_hit()) def test_deal_card(self): player = Player() hand_size = len(player.hand) self.dealer.deal_card(player) self.assertEquals(hand_size + 1, len(player.hand)) def test_reveal_hole_card(self): self.assertFalse(self.dealer.is_hole_card_visible) self.dealer.reveal_hole_card() self.assertTrue(self.dealer.is_hole_card_visible)
def teste_empate_inicio_rodada(): dealer = Dealer() jogador = Jogador('teste') jogador.receber_cartas([Carta('6', ''), Carta('A', ''), Carta('3', '')]) dealer.receber_cartas([Carta('Q', ''), Carta('Q', '')]) assert dealer.resultado_jogador(jogador) == 0
def teste_vitoria_jogador_com_blackjack(): dealer = Dealer() jogador = Jogador('teste') jogador.receber_cartas([Carta('10', ''), Carta('A', '')]) dealer.receber_cartas([Carta('J', ''), Carta('9', '')]) assert dealer.resultado_jogador(jogador) == 1
def test_get_action(self): """A test which makes sure that the get_action method of the Dealer class functions properly.""" # Try several test cases test_cases = [ [Card("Clubs", "2"), Card("Clubs", "2"), "Hit"], [Card("Clubs", "10"), Card("Clubs", "10"), "Stand"], [Card("Clubs", "10"), Card("Clubs", "7"), "Stand"], [Card("Clubs", "10"), Card("Clubs", "6"), "Hit"], [Card("Clubs", "Ace"), Card("Clubs", "6"), "Hit"], [Card("Clubs", "Ace"), Card("Clubs", "6"), Card("Clubs", "10"), "Stand"], [Card("Clubs", "Jack"), Card("Clubs", "7"), "Stand"], [Card("Clubs", "Queen"), Card("Clubs", "6"), "Hit"], [Card("Clubs", "King"), Card("Clubs", "6"), "Hit"], [Card("Clubs", "Ace"), Card("Clubs", "Ace"), Card("Clubs", "6"), "Hit"], [Card("Clubs", "Ace"), Card("Clubs", "Ace"), Card("Clubs", "6"), "Hit"], [Card("Clubs", "7"), Card("Clubs", "8"), "Hit"], [Card("Clubs", "7"), Card("Clubs", "8"), Card("Clubs", "Ace"), "Hit"], [Card("Clubs", "7"), Card("Clubs", "8"), Card("Clubs", "2"), "Stand"], [Card("Clubs", "Jack"), Card("Clubs", "Queen"), "Stand"], ] for case in test_cases: dealer = Dealer() cards = len(case) - 1 for index in range(cards): dealer.add_card(case[index]) action = dealer.get_action() self.assertEqual( action.move, case[-1], msg="The test of the get_action method with the index of " + str(test_cases.index(case)) + " failed.", )
def test_dealer_take_100_from_player_dollars_then_he_or_she_give_100_chips_to_player(self): player = PlayerBuilder().withCash(100).create() dealer = Dealer() dealer.buyChips(player, 100) self.assertEqual(player.chips, 100)
def teste_dealer_52_cartas_antes_do_inicio_de_qualquer_rodada(): # Quando inicia o jogo, todas as cartas são # devolvidas, tendo um total de 52, portanto # se o jogo for iniciado duas vezes, o total deve # após o inicio deve ser 45 em ambas (-5 de descarte, -2 para o Dealer) dealer = Dealer() dealer.iniciar_jogo() dealer.iniciar_jogo() assert dealer.quantidade_cartas_baralho() == 45
def test_dealer_call_security_if_player_younger_18_years_old_buying_chips(self): player = PlayerBuilder().withAge(17).create() dealer = Dealer() res = False try: dealer.buyChips(player, 100) except YoungerPlayer: res = True self.assertEqual(res, True)
def teste_derrota_jogador_com_soma_maior_que_21(): dealer = Dealer() jogador = Jogador('teste') jogador.receber_cartas( [Carta('A', ''), Carta('A', ''), Carta('10', ''), Carta('10', '')]) dealer.receber_cartas([Carta('J', ''), Carta('2', '')]) assert dealer.resultado_jogador(jogador) == -1
def test_determine_winners(self): """ Test that the dealer hits at the appropriate times and that winning hands are appropriated updated as such. """ # setup deck deck = Deck() deck.create() deck.shuffle() # setup gambler, dealer & hands dealer = Dealer() dealer_hand = Hand() dealer.hands.append(dealer_hand) gambler = Gambler("Test") gambler_hand = Hand() gambler.hands.append(gambler_hand) players = [gambler, dealer] # must hit a soft 17 (A, 6) gambler_hand.final_value = 20 dealer_hand.cards.append(Card('Hearts', 'Ace', 1)) dealer_hand.cards.append(Card('Hearts', 'Six', 6)) bj.determine_winners(players, deck) self.assertTrue(len(dealer_hand.cards) > 2) # must hit on 16 or less (K, 6) self.reset_hand_attrs(dealer_hand) dealer_hand.cards.append(Card('Hearts', 'King', 10)) dealer_hand.cards.append(Card('Hearts', 'Six', 6)) bj.determine_winners(players, deck) self.assertTrue(len(dealer_hand.cards) > 2) # check dealer bust (K, 6, J) dealer_hand.cards.pop() dealer_hand.cards.append(Card('Hearts', 'Jack', 10)) bj.determine_winners(players, deck) self.assertTrue(dealer_hand.busted) self.assertTrue(gambler_hand.win) # check dealer stands on 17 (K, 7) self.reset_hand_attrs(dealer_hand) dealer_hand.cards.append(Card('Hearts', 'King', 10)) dealer_hand.cards.append(Card('Hearts', 'Seven', 7)) bj.determine_winners(players, deck) self.assertTrue(len(dealer_hand.cards) == 2) # gambler wins with 20 to dealer's 17 self.assertTrue(gambler_hand.win) # check dealer stands on soft 18 (Ace, 7) self.reset_hand_attrs(dealer_hand) dealer_hand.cards.append(Card('Hearts', 'Ace', 1)) dealer_hand.cards.append(Card('Hearts', 'Seven', 7)) bj.determine_winners(players, deck) self.assertTrue(len(dealer_hand.cards) == 2)
def __init__(self): # game logic related self.pot = 0 self.player = Player() self.dealer = Dealer() # interface related - add interface elements here self.root = Tk() self.root.title('Casino') self.root.iconbitmap( 'C:/Users/SavSamuShaman/Desktop/blackjack/pkc2.ico') # labels self.header_label = Label( self.root, text="You walk to the table and the dealer ask for your name") self.message_label = Label( self.root, text='Best of luck a the blackjack table ;)') self.error_message_label = Label(self.root) self.player_money_label = Label( self.root, text=f'Your money : {self.player.chips}') self.dealer_money_label = Label( self.root, text=f'Dealer money : {self.dealer.chips}') self.pot_label = Label(self.root, text=f'Pot : 0') self.current_score_label = Label(self.root, text=f'Current score : 0') # buttons self.hit_me_button = Button(self.root, text='Hit me', command=self.hit_me) self.stay_button = Button(self.root, text='Stay', command=self.stay) self.bet_button = Button(self.root, text='Bet', command=self.bet) self.start_button = Button(self.root, text='Tell the dealer your name', command=self.set_up_environ) # input box self.entry = Entry(self.root, width=30) # element placement self.header_label.grid(row=0, column=1) self.entry.grid(row=1, column=1, columnspan=3) self.start_button.grid(row=2, column=1, padx=15, pady=20) self.root.mainloop()
def UImain(): used_cards = [] cards_showing = [] deck = [] for decks in range(1): for val in VALS: for suit in SUITS: deck.append(Card(suit, val)) random.shuffle(deck) blank_card = Card('Plastic', 'Blank') rand_index = 8 + random.randint(-4, 4) deck.insert(rand_index, blank_card) player1 = UIPlayer(200.0, deck, used_cards, cards_showing) dealer = Dealer(deck, used_cards, cards_showing) while player1.balence > 0: os.system('cls' if os.name == 'nt' else 'clear') print('Balence:', player1.balence) s = int(input('Place wager amount: ')) player1.set_wager(s) deal_cards([dealer, player1]) # UI player loop while (player1.status != Status.STAND): print_UI(dealer, player1) player1.move() while dealer.status != Status.STAND: print_UI(dealer, player1, dealer_move=True) dealer.move() time.sleep(1) print_UI(dealer, player1, dealer_move=True) dealer_hand_val = dealer.best_hand_val() p_hand_val = player1.best_hand_val() if p_hand_val > 21 or p_hand_val <= 0: print('You lose', player1.wager) player1.lose() elif player1.has_blackjack() and not dealer.has_blackjack(): print('You win', player1.wager) player1.win() elif not player1.has_blackjack() and dealer.has_blackjack(): print('You lose', player1.wager) player1.lose() elif p_hand_val > dealer_hand_val: print('You win', player1.wager) player1.win() elif p_hand_val < dealer_hand_val: print('You lose', player1.wager) player1.lose() input('\nhit any key to continue ') clear_table([dealer, player1])
def main(): # Initialize game_over = False deck = build_deck() used_cards = [] p1 = Player(deck, used_cards) dealer = Dealer(deck, used_cards) players = [p1, dealer] while not game_over: get_wager() deal_cards([p1, dealer]) p1_move() dealer_move() eval_hands() clear_table([p1, dealer])
def check_hands_test(self): p1 = Player() p1.add_card(Card("ace", "spades")) p1.add_card(Card("jack", "hearts")) self.assertEqual("ace of spades & jack of hearts", p1.print_hand()) p2 = Dealer() p2.add_card(Card("one", "spades")) p2.add_card(Card("ten", "diamonds")) self.assertEqual("XX & ten of diamonds", p2.print_hand())
def main(): """Plays the Game""" os.system('clear') player_name = input("Please enter your name: ") p1 = HumanPlayer(player_name, BlackjackHand()) print("\nWelcome to Bull City Bets - an exclusive Blackjack Casino!\n\n") while True: d1 = Dealer("dealer", BlackjackHand()) deck = Deck() g = Game(p1, d1, deck) print("\nAnte Up!") p1.place_bet() g.add_bet() print("Total Pot: {} Player Purse: {}".format(g.pot, p1.purse)) if not g.check_initial_blackjack(): g.player_turn() g.dealer_turn() g.print_results() g.play_again()
def teste_dealer_43_cartas_apos_entregar_as_do_jogador_em_duas_rodadas(): dealer = Dealer() jogador = Jogador('teste') dealer.iniciar_jogo() jogador.receber_cartas(dealer.entregar_cartas_jogador()) assert dealer.quantidade_cartas_baralho() == 43 dealer.receber_cartas_jogador(jogador.entregar_cartas()) dealer.iniciar_jogo() jogador.receber_cartas(dealer.entregar_cartas_jogador()) assert dealer.quantidade_cartas_baralho() == 43
def test_build_deck_has_52_cards(self): deck = Dealer.build_deck() self.assertEquals(52, len(deck))
class SetupGame: def __init__(self): # game logic related self.pot = 0 self.player = Player() self.dealer = Dealer() # interface related - add interface elements here self.root = Tk() self.root.title('Casino') self.root.iconbitmap( 'C:/Users/SavSamuShaman/Desktop/blackjack/pkc2.ico') # labels self.header_label = Label( self.root, text="You walk to the table and the dealer ask for your name") self.message_label = Label( self.root, text='Best of luck a the blackjack table ;)') self.error_message_label = Label(self.root) self.player_money_label = Label( self.root, text=f'Your money : {self.player.chips}') self.dealer_money_label = Label( self.root, text=f'Dealer money : {self.dealer.chips}') self.pot_label = Label(self.root, text=f'Pot : 0') self.current_score_label = Label(self.root, text=f'Current score : 0') # buttons self.hit_me_button = Button(self.root, text='Hit me', command=self.hit_me) self.stay_button = Button(self.root, text='Stay', command=self.stay) self.bet_button = Button(self.root, text='Bet', command=self.bet) self.start_button = Button(self.root, text='Tell the dealer your name', command=self.set_up_environ) # input box self.entry = Entry(self.root, width=30) # element placement self.header_label.grid(row=0, column=1) self.entry.grid(row=1, column=1, columnspan=3) self.start_button.grid(row=2, column=1, padx=15, pady=20) self.root.mainloop() def set_up_environ(self): name_input = self.entry.get() if name_input: self.player.name = name_input self.entry.delete(0, END) self.entry.grid_forget() self.start_button.grid_forget() # reusing existing elements self.header_label[ 'text'] = 'The Red Sparrow welcomes you, {name}'.format( name=self.player.name) self.start_button['text'] = 'Begin' self.start_button['command'] = self.new_round self.start_button.grid(row=4, column=1) self.message_label.grid(row=2, column=1) self.player_money_label.grid(row=3, column=2) self.dealer_money_label.grid(row=3, column=0) self.pot_label.grid(row=3, column=1) return def bet(self): """Clears variables and starts a new round on valid bet""" try: amount = int(self.entry.get()) if amount > self.player.chips: self.error_message_label['text'] = 'Not enough money' self.error_message_label.grid(row=6, column=1) return self.clear_game() self.pot += self.player.bet(amount) + self.dealer.bet(amount) self.entry.grid_forget() self.bet_button.grid_forget() self.error_message_label.grid_forget() self.entry.delete(0, END) self.current_score_label['text'] = 'Current score : 0' self.message_label[ 'text'] = 'Best of luck a the blackjack table ;)' self.pot_label['text'] = 'Pot :{pot}'.format(pot=self.pot) self.update_money_labels() self.current_score_label.grid(row=4, column=1) self.stay_button.grid(row=4, column=0) self.hit_me_button.grid(row=4, column=2) except ValueError: self.error_message_label['text'] = 'Invalid bet' self.error_message_label.grid(row=6, column=1) return def hit_me(self): # hit me --> deal me a card in blackjack card = self.dealer.deal_card() self.player.add_to_score(card) player_score = self.player.current_score if player_score < 21: pass elif player_score == 21: self.player.win(self.pot) self.message_label['text'] = f'{self.player.name} has Blackjack !' self.conclude_round() else: self.dealer.win(self.pot) self.message_label['text'] = f'{self.player.name} busted out' self.conclude_round() self.current_score_label['text'] = 'Current score : {score}'.format( score=player_score) return def stay(self): player_score = self.player.current_score player_points = abs(21 - player_score) dealer_points = abs(21 - conclude_game(self.dealer)) if dealer_points < player_points: self.dealer.win(self.pot) self.message_label[ 'text'] = f'The dealer was closer to 21. You lose' elif dealer_points == player_points: self.dealer.win(self.pot / 2) self.player.win(self.pot / 2) self.message_label['text'] = "It's a tie" else: self.player.win(self.pot) self.message_label['text'] = f"You win ${self.pot}" self.current_score_label[ 'text'] = f'Your score : {player_score} \nDealer score {self.dealer.current_score}' self.conclude_round() return def new_round(self): self.start_button.grid_forget() self.entry.grid(row=5, column=1) self.bet_button.grid(row=5, column=2) return def conclude_round(self): self.update_money_labels() self.hit_me_button.grid_forget() self.stay_button.grid_forget() self.new_round() return def clear_game(self): self.dealer.clear_score() self.player.clear_score() self.pot = 0 return def update_money_labels(self): self.dealer_money_label['text'] = f'Dealer money : {self.dealer.chips}' self.player_money_label['text'] = f'Player money : {self.player.chips}' return
def setUp(self): self.testPlayer = Player() self.testDealer = Dealer() self.winner = None
def test_settle_up(self): """ Test that settle_up() function accurately updates each players .money attribute for various outcomes. """ # setup players dealer = Dealer() player = Gambler('Test') players = [player, dealer] # setup hands dealer_hand = Hand() dealer.hands.append(dealer_hand) hand = Hand() player.hands.append(hand) # check loss player.money = 500 hand.wager = 100 bj.settle_up(players) self.assertEqual(player.money, 400) # check win hand.win = True bj.settle_up(players) self.assertEqual(player.money, 500) # check push hand.win = False hand.push = True bj.settle_up(players) self.assertEqual(player.money, 500) # check insurance w/ dealer blackjack dealer_hand.blackjack = True hand.insurance = True bj.settle_up(players) self.assertEqual(player.money, 550) hand.insurance = False bj.settle_up(players) self.assertEqual(player.money, 550) # check insurance w/o dealer blackjack dealer_hand.blackjack = False hand.insurance = True bj.settle_up(players) self.assertEqual(player.money, 500) hand.insurance = False bj.settle_up(players) self.assertEqual(player.money, 500) # check Blackjack hand.push = False hand.blackjack = True bj.settle_up(players) self.assertEqual(player.money, 650) # check blackjack with fractional dollars hand.wager = 5 bj.settle_up(players) self.assertEqual(player.money, 657.5) # check dealer blackjack dealer_hand.blackjack = True hand.blackjack = False bj.settle_up(players) self.assertEqual(player.money, 652.5)
return self.A[1] if player_points < 12: return self.A[0] else: A, Q = self.A, self.Q s = self.get_state_name(dealer) if epsilon is None: epsilon = 1.0 / ( 1 + 4 * math.log10(1 + player.total_learning_times)) return epsilon_greedy_policy(A, s, Q, epsilon) A = ["继续叫牌", "停止叫牌"] display = False player = MC_Player(A=A, display=display) dealer = Dealer(A=A, display=display) arena = Arena(A=A, display=display) arena.play_games(dealer=dealer, player=player, num=200000, show_statistic=True) draw_value(player.Q, useable_ace=True, is_q_dict=True, A=player.A) draw_policy(epsilon_greedy_policy, player.A, player.Q, epsilon=1e-10, useable_ace=True) draw_value(player.Q, useable_ace=False, is_q_dict=True, A=player.A) draw_policy(epsilon_greedy_policy, player.A, player.Q, epsilon=1e-10, useable_ace=False)
class TestBlackWinnerLogic(unittest.TestCase): def setUp(self): self.testPlayer = Player() self.testDealer = Dealer() self.winner = None def tearDown(self): del self.testPlayer del self.testDealer def test_Winnner_push(self): # both player and dealer have Ace and Face card self.testPlayer.recieve_card( Card(CardFaceType.ACE, SuitType.CLUB, CardFaceState.UP)) self.testPlayer.recieve_card( Card(CardFaceType.JACK, SuitType.HEART, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.KING, SuitType.DIAMOND, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.ACE, SuitType.SPADE, CardFaceState.UP)) self.winner = blackjack.determine_blackjack_winner( self.testPlayer, self.testDealer) self.assertTrue((self.winner is None), "there should be no winner here") def test_Winner_playerBust(self): # dealer has lower hand, player busts self.testPlayer.recieve_card( Card(CardFaceType.KING, SuitType.CLUB, CardFaceState.UP)) self.testPlayer.recieve_card( Card(CardFaceType.JACK, SuitType.HEART, CardFaceState.UP)) self.testPlayer.recieve_card( Card(CardFaceType.FIVE, SuitType.DIAMOND, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.KING, SuitType.DIAMOND, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.ACE, SuitType.SPADE, CardFaceState.UP)) self.winner = blackjack.determine_blackjack_winner( self.testPlayer, self.testDealer) self.assertIsInstance(self.winner, Dealer, "Dealer should have won") def test_winner_dealerBust(self): # player has lower hand, dealer busts self.testPlayer.recieve_card( Card(CardFaceType.SIX, SuitType.CLUB, CardFaceState.UP)) self.testPlayer.recieve_card( Card(CardFaceType.JACK, SuitType.HEART, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.KING, SuitType.DIAMOND, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.TEN, SuitType.DIAMOND, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.ACE, SuitType.SPADE, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.FOUR, SuitType.DIAMOND, CardFaceState.UP)) self.winner = blackjack.determine_blackjack_winner( self.testPlayer, self.testDealer) self.assertIsInstance(self.winner, Player, "Player should have won") def test_winner_playerBlackjack(self): # player has a blackjack self.testPlayer.recieve_card( Card(CardFaceType.ACE, SuitType.CLUB, CardFaceState.UP)) self.testPlayer.recieve_card( Card(CardFaceType.JACK, SuitType.HEART, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.KING, SuitType.DIAMOND, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.NINE, SuitType.SPADE, CardFaceState.UP)) self.winner = blackjack.determine_blackjack_winner( self.testPlayer, self.testDealer) self.assertIsInstance(self.winner, Player, "Player Should have won") def test_winner_dealerBlackJack(self): # dealer has blackjack self.testPlayer.recieve_card( Card(CardFaceType.SEVEN, SuitType.CLUB, CardFaceState.UP)) self.testPlayer.recieve_card( Card(CardFaceType.JACK, SuitType.HEART, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.KING, SuitType.DIAMOND, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.ACE, SuitType.SPADE, CardFaceState.UP)) self.winner = blackjack.determine_blackjack_winner( self.testPlayer, self.testDealer) self.assertIsInstance(self.winner, Dealer, "Dealer should have won") def test_winner_player(self): #player has better hand < blackJack self.testPlayer.recieve_card( Card(CardFaceType.NINE, SuitType.CLUB, CardFaceState.UP)) self.testPlayer.recieve_card( Card(CardFaceType.EIGHT, SuitType.HEART, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.KING, SuitType.DIAMOND, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.THREE, SuitType.SPADE, CardFaceState.UP)) self.winner = blackjack.determine_blackjack_winner( self.testPlayer, self.testDealer) self.assertIsInstance(self.winner, Player, "Player should have won") def test_winner_dealer(self): #dealer has better hand < blackJack self.testPlayer.recieve_card( Card(CardFaceType.TWO, SuitType.CLUB, CardFaceState.UP)) self.testPlayer.recieve_card( Card(CardFaceType.NINE, SuitType.HEART, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.KING, SuitType.DIAMOND, CardFaceState.UP)) self.testDealer.recieve_card( Card(CardFaceType.SIX, SuitType.SPADE, CardFaceState.UP)) self.winner = blackjack.determine_blackjack_winner( self.testPlayer, self.testDealer) self.assertIsInstance(self.winner, Dealer, "Dealer should have won")
def teste_dealer_52_cartas_antes_do_inicio_da_rodada(): dealer = Dealer() assert dealer.quantidade_cartas_baralho() == 52
def step_impl(context, hand): context.dealer = Dealer() context.dealer.hand = hand.split(',')
def step_impl(context): context.dealer = Dealer()
def setUp(self): self.dealer = Dealer()
class TestDealer(unittest.TestCase): def setUp(self): self.dealer = Dealer(cash_balance=100) def tearDown(self): del self.dealer def test_dealer_match_bet_negative_value(self): self.assertEqual( self.dealer.match_bet(-50), 50, 'Match bet methods accepts negative value. Check if absolute value implemented or if try catch statement present.' ) def test_dealer_match_bet_ten_dollar(self): self.assertEqual(self.dealer.match_bet(10), 10, 'Match bet is not matching bets correctly.') def test_dealer_match_bet_bigger_than_cash_balance_value(self): self.assertRaises(SystemExit, self.dealer.match_bet, 110) def test_dealer_match_bet_bigger_than_cash_balance_in_absolute_value(self): self.assertRaises(SystemExit, self.dealer.match_bet, -110) def test_dealer_match_bet_cash_balance_negative_value(self): self.dealer.match_bet(-10) self.assertEqual( self.dealer.cash_balance, 90, 'Cash balance not being substracted while allocating bets.') def test_dealer_match_bet_cash_balance_positive_value(self): self.dealer.match_bet(10) self.assertEqual( self.dealer.cash_balance, 90, 'Cash balance not being substracted while allocating bets.') def test_dealer_match_bet_cash_balance_equivalent_value(self): self.dealer.match_bet(100) self.assertEqual( self.dealer.cash_balance, 0, 'Match bet is not set to to accept bet equal to the cash balance. Check method implementation.' ) def test_dealer_is_soft_17_true_card_values_less_than_seventeen_and_two_cards( self): self.dealer.hand.add_card( [Card('Spades', 'Jack'), Card('Diamonds', 'Five')]) self.assertTrue(self.dealer.is_soft_17(), 'Is soft 17 no detecting soft 17.') def test_dealer_is_soft_17_true_card_values_less_than_seventeen_and_three_cards( self): self.dealer.hand.add_card([ Card('Spades', 'Four'), Card('Diamonds', 'Five'), Card('Hearts', 'Two') ]) self.assertTrue(self.dealer.is_soft_17(), 'Is soft 17 no detecting soft 17.') def test_dealer_is_soft_17_false_card_values_less_than_seventeen_and_four_cards( self): self.dealer.hand.add_card([ Card('Spades', 'Four'), Card('Diamonds', 'Five'), Card('Hearts', 'Two'), Card('Clubs', 'Three') ]) self.assertFalse(self.dealer.is_soft_17(), 'Is soft 17 no detecting soft 17.') def test_dealer_is_soft_17_false_seventeen_exactly(self): self.dealer.hand.add_card( [Card('Spades', 'Jack'), Card('Diamonds', 'Seven')]) self.assertFalse(self.dealer.is_soft_17(), 'Is soft 17 no detecting soft 17.') def test_dealer_is_soft_17_false_superior_to_seventeen(self): self.dealer.hand.add_card( [Card('Spades', 'Jack'), Card('Diamonds', 'Queen')]) self.assertFalse(self.dealer.is_soft_17(), 'Is soft 17 no detecting soft 17.') def test_dealer_return_card_to_deck_multiple_cards(self): self.dealer.hand.add_card(self.dealer.deck.deal_two_cards()) self.dealer.return_cards_to_deck(self.dealer.hand.hand) self.assertEqual(len(self.dealer.deck), 52, 'Return card to deck not working.') def test_dealer_return_card_to_deck_one_card(self): self.dealer.hand.add_card(self.dealer.deck.deal_one_card()) self.dealer.return_cards_to_deck(self.dealer.hand.hand) self.assertEqual(len(self.dealer.deck), 52, 'Return card to deck not working.') def test_dealer_add_cash_to_balance_negative(self): self.dealer.add_to_cash_balance(-10) self.assertEqual(self.dealer.cash_balance, 110, 'Add cash to balance not working properly.') def test_dealer_add_cash_to_balance_positive(self): self.dealer.add_to_cash_balance(10) self.assertEqual(self.dealer.cash_balance, 110, 'Add cash to balance not working properly.') def test_dealer_add_cash_to_balance_zero(self): self.dealer.add_to_cash_balance(0) self.assertEqual(self.dealer.cash_balance, 100, 'Add cash to balance not working properly.')
def step_impl(context, total): context.dealer = Dealer() context.total = total
def teste_somatorio_cartas(): dealer = Dealer() assert dealer.somatorio_cartas( [Carta('9', ''), Carta('A', ''), Carta('A', '')]) == 21 assert dealer.somatorio_cartas([ Carta('7', ''), Carta('A', ''), Carta('A', ''), Carta('A', ''), Carta('A', '') ]) == 21 assert dealer.somatorio_cartas( [Carta('7', ''), Carta('A', ''), Carta('A', ''), Carta('A', '')]) == 20 assert dealer.somatorio_cartas( [Carta('8', ''), Carta('A', ''), Carta('A', ''), Carta('A', '')]) == 21 assert dealer.somatorio_cartas([ Carta('9', ''), Carta('A', ''), Carta('A', ''), Carta('A', ''), Carta('A', '') ]) == 13 assert dealer.somatorio_cartas([ Carta('10', ''), Carta('A', ''), Carta('A', ''), Carta('A', ''), Carta('A', '') ]) == 14 assert dealer.somatorio_cartas( [Carta('J', ''), Carta('A', ''), Carta('A', ''), Carta('3', '')]) == 15 assert dealer.somatorio_cartas( [Carta('J', ''), Carta('A', ''), Carta('A', '')]) == 12 assert dealer.somatorio_cartas( [Carta('A', ''), Carta('A', ''), Carta('A', ''), Carta('A', '')]) == 14 assert dealer.somatorio_cartas( [Carta('2', ''), Carta('5', ''), Carta('9', ''), Carta('A', '')]) == 17 assert dealer.somatorio_cartas( [Carta('2', ''), Carta('6', ''), Carta('9', ''), Carta('4', '')]) == 21 assert dealer.somatorio_cartas([Carta('A', ''), Carta('A', '')]) == 12 assert dealer.somatorio_cartas( [Carta('A', ''), Carta('A', ''), Carta('J', '')]) == 12 assert dealer.somatorio_cartas( [Carta('10', ''), Carta('J', ''), Carta('A', ''), Carta('A', '')]) == 22 assert dealer.somatorio_cartas([ Carta('10', ''), Carta('J', ''), Carta('A', ''), Carta('A', ''), Carta('A', '') ]) == 23 assert dealer.somatorio_cartas([ Carta('10', ''), Carta('J', ''), Carta('2', ''), Carta('2', ''), Carta('A', '') ]) == 25 assert dealer.somatorio_cartas( [Carta('10', ''), Carta('J', ''), Carta('3', ''), Carta('A', '')]) == 24 assert dealer.somatorio_cartas([ Carta('10', ''), Carta('J', ''), Carta('3', ''), Carta('A', ''), Carta('A', '') ]) == 25 assert dealer.somatorio_cartas( [Carta('10', ''), Carta('A', ''), Carta('A', ''), Carta('J', '')]) == 22 assert dealer.somatorio_cartas( [Carta('10', ''), Carta('5', ''), Carta('2', ''), Carta('3', '')]) == 20 assert dealer.somatorio_cartas([ Carta('10', ''), Carta('5', ''), Carta('2', ''), Carta('3', ''), Carta('A', '') ]) == 21 assert dealer.somatorio_cartas( [Carta('10', ''), Carta('Q', ''), Carta('A', '')]) == 21 assert dealer.somatorio_cartas( [Carta('10', ''), Carta('K', ''), Carta('2', '')]) == 22 assert dealer.somatorio_cartas([Carta('J', ''), Carta('2', '')]) == 12 assert dealer.somatorio_cartas([Carta('A', ''), Carta('A', '')]) == 12 assert dealer.somatorio_cartas( [Carta('A', ''), Carta('A', ''), Carta('9', '')]) == 21
"five,diamonds", "four,diamonds", "three,diamonds", "two,diamonds"] def deal_card(): playing_card = random.choice(deck) deck.remove(playing_card) return playing_card if __name__ == '__main__': play_game = True while play_game: print "---- Start of Round ----" print "dealing cards ...." dealer = Dealer() # Deal 2 cards for Dealer rank, suit = deal_card().split(',') dealer.add_card(Card(rank,suit)) rank, suit = deal_card().split(',') dealer.add_card(Card(rank,suit)) # Deal player cards player = Player() rank, suit = deal_card().split(',') player.add_card(Card(rank,suit)) rank, suit = deal_card().split(',') player.add_card(Card(rank,suit))
def teste_dealer_descartes_inicio_jogo(): dealer = Dealer() dealer.iniciar_jogo() assert dealer.quantidade_cartas_baralho() == 45
def setUp(self): self.dealer = Dealer(cash_balance=100)
def teste_dealer_quantidade_cartas_baralho(): dealer = Dealer() assert dealer.quantidade_cartas_baralho() == 52