def test_blackjack_player_wins(self): player = Player('cory','password') game = Game('Blackjack') hand = Hand() player.bank = 100 player.hands.append(hand) game.hands.append(hand) game.players.append(player) bank_before_bet = player.bank # cards_app.session.commit() cards_app.session.flush() bet(hand, 50) cards = [Card(sequence=1), Card(sequence=10)] hand.cards.extend(cards) count_blackjack(hand) evaluate_hit(hand) # player wins with nautral evaluate_hit assert player.bank == bank_before_bet - 50 # player stands on 18, dealer stands on 17 hand.cards = [Card(sequence=10), Card(sequence=8)] bet(hand, 50) game.dealer = Player('cory','password') dealer = game.dealer dealer.cards = [Card(sequence=10), Card(sequence=17)] dealer_hand = Hand() dealer_hand.cards = dealer.cards
def test_blackjack_payout(self): player = Player('cory','password') game = Game('Blackjack') hand = Hand() game.players = [] player.bank = 100 player.hands = [hand] hand.bet = 0 game.deck = Hand() game.dealer = Player('cory','password') game.dealer.hands.append(Hand()) game.hands.append(game.dealer.hands[0]) player.hands.append(hand) game.hands.append(hand) game.deck.cards = piece_maker(suits, card_values, 1) game.players.append(player) cards_app.session.flush() # testing player AND dealer get blackjack hand.cards = [Card(sequence=1), Card(sequence=10)] game.dealer.hands[0].cards = [Card(sequence=1), Card(sequence=10)] bet(hand, 50) count_blackjack(hand) blackjack_dealer(game) assert player.bank == 100 # Player gets 15 and dealer gets 15, dealer hits and breaks because deck is unshuffled and king on top player.bank = 100 hand.cards = [Card(sequence=10), Card(sequence=5)] game.dealer.hands[0].cards = [Card(sequence=10), Card(sequence=5)] bet(hand, 50) hand.is_expired = False count_blackjack(hand) blackjack_dealer(game) assert player.bank == 150 # player gets blackjack, dealer doesn't hand.is_expired = False hand.bet = 0 player.bank = 100 hand.cards = [Card(sequence=10), Card(sequence=1)] game.dealer.hands[0].cards = [Card(sequence=10), Card(sequence=10)] bet(hand, 50) count_blackjack(hand) blackjack_dealer(game) assert player.bank == 175 # player broke, loses bet hand.is_expired = False hand.bet = 0 player.bank = 100 hand.cards = [Card(sequence=10), Card(sequence=10), Card(sequence=10)] game.dealer.hands[0].cards = [Card(sequence=10), Card(sequence=10)] bet(hand, 50) count_blackjack(hand) blackjack_dealer(game) blackjack_payout(game) assert player.bank == 50
def split(hand): player = hand.player game = hand.game new_hand = Hand() new_hand.cards = [hand.cards.pop()] game.hands.append(new_hand) player.hands.append(new_hand) new_hand.cards.append(game.deck.cards.pop()) hand.cards.append(game.deck.cards.pop())
def split(hand_id): hand = session.query(Hand).filter(Hand.id == hand_id).all()[0] player = hand.player game = hand.game new_hand = Hand() count_blackjack(hand) session.add(new_hand) new_hand.cards = [hand.cards.pop()] game.hands.append(new_hand) player.hands.append(new_hand) new_hand.cards.append(game.deck.cards.pop()) hand.cards.append(game.deck.cards.pop()) session.commit() return jsonify({'status': 'success'})
def test_blackjack_player_loses(self): game = Game('Blackjack') cards = [Card(sequence=10), Card(sequence=10), Card(sequence=10)] player = Player('cory','password') cards_app.session.add(player) hand = Hand() player.hands.append(hand) game.players.append(player) game.hands.append(hand) cards_app.session.flush() hand.cards.extend(cards) bank_after_bet = player.bank count_blackjack(hand) evaluate_hit(hand) # player loses if he breaks assert player.bank == bank_after_bet # start of next loss, player stands on 15, dealer gets high hand hand.cards = [Card(sequence=10), Card(sequence=5)] bet(hand, 50) bank_after_bet = player.bank count_blackjack(hand) evaluate_hit(hand) assert player.bank == bank_after_bet