Example #1
0
 def test_picture_card_score_calculation(self):
     """
     Test that picture cards (King, Queen, Jack) all return a score of 10
     """
     self.assertEqual(card(11, "H").get_score(), 10)
     self.assertEqual(card(12, "H").get_score(), 10)
     self.assertEqual(card(13, "H").get_score(), 10)
def create_deck():
	deck = []
	counter = 1
	while counter <= 40:
		if counter <= 8:
			deck.append(cards.card("Bun", 1))
		elif counter > 8 and counter <= 16:
			deck.append(cards.card("Patty", 1))
		elif counter > 16 and counter <= 20:
			deck.append(cards.card("Lettuce", 2))
		elif counter > 20 and counter <= 24:
			deck.append(cards.card("Tomato", 2))
		elif counter > 24 and counter <= 27:
			deck.append(cards.card("Onion", 3))
		elif counter > 27 and counter <= 29:
			deck.append(cards.card("Pickle", 4))
		elif counter > 29 and counter <= 34:
			deck.append(cards.card("Exercise", -2))
		elif counter > 34 and counter <= 37:
			deck.append(cards.card("Laxative", -3))
		elif counter > 37 and counter <= 39:
			deck.append(cards.card("Ketchup", 2))
		elif counter == 40:
			deck.append(cards.card("Mayo", 3))
		counter += 1
	random.shuffle(deck)
	return deck
Example #3
0
 def test_card_creation(self):
     """
     Test that cards can be created successfully and that values are correct for Aces, numbers
     and pictures (king, queen, jack)
     """
     self.assertEqual(card(1, "H").get_card_details(), "AH")
     self.assertEqual(card(4, "H").get_card_details(), "4H")
     self.assertEqual(card(11, "H").get_card_details(), "JH")
     self.assertEqual(card(12, "H").get_card_details(), "QH")
     self.assertEqual(card(13, "H").get_card_details(), "KH")
Example #4
0
 def test_dealer_stands_on_soft_17(self):
     """
     Test that a dealer always stands when they have a soft 17 (a 17 that could also be a 7 e.g. 6 + A or 3 + 3 + A)
     """
     dealer = self.dealer
     test_shoe = self.test_shoe
     test_shoe.cards.insert(0, card(1, "S"))
     test_shoe.cards.insert(3, card(3, "S"))
     player_list = self.test_player_list
     initial_deal(test_shoe, player_list, dealer)
     self.assertTrue(dealer.soft_score_check())
     self.assertFalse(dealer_play(test_shoe, dealer))
     self.assertEqual(dealer.get_score(), 17)
Example #5
0
 def test_user_stands_with_blackjack(self):
     """
     Test that a user automatically stands when they have blackjack
     """
     test_shoe = self.test_shoe
     player_list = self.test_player_list
     dealer = self.dealer
     player = player_list[0]
     test_shoe.cards.insert(0, card(10, "H"))
     test_shoe.cards.insert(2, card(1, "H"))
     initial_deal(test_shoe, player_list, dealer)
     self.assertEqual(player.get_score(), 21)
     self.assertTrue(check_blackjack(player.get_score(), player.get_hand()))
Example #6
0
 def test_user_busts(self):
     """
     Test that a user's turn ends when they bust and that they also lose
     """
     test_shoe = self.test_shoe
     player_list = self.test_player_list
     dealer = self.dealer
     player = player_list[0]
     test_shoe.cards.insert(0, card(10, "H"))
     test_shoe.cards.insert(2, card(3, "H"))
     test_shoe.cards.insert(4, card(10, "D"))
     initial_deal(test_shoe, player_list, dealer)
     with mock.patch('builtins.input', return_value="hit"):
         user_play(test_shoe, player, dealer)
     self.assertTrue(player.check_bust)
Example #7
0
 def updata(self,data):
     i=0
     for p in self._players:
         temp=[]
         for name in data[i]:
             temp.append(card(name))
         p.handcard=temp
Example #8
0
 def test_user_stands_on_21(self):
     """
     Test that a user automatically stands when they hit 21
     """
     test_shoe = self.test_shoe
     player_list = self.test_player_list
     dealer = self.dealer
     player = player_list[0]
     test_shoe.cards.insert(0, card(10, "H"))
     test_shoe.cards.insert(2, card(3, "H"))
     test_shoe.cards.insert(4, card(8, "D"))
     initial_deal(test_shoe, player_list, dealer)
     with mock.patch('builtins.input', return_value="hit"):
         user_play(test_shoe, player, dealer)
     self.assertEqual(player.get_score(), 21)
     self.assertFalse(check_blackjack(player.get_score(),
                                      player.get_hand()))
Example #9
0
def ai_single(hand, deck):
	test_card = cards.card("null", 0)
	current_largest = test_card
	for x in hand:
		if x.get_value() > current_largest.get_value() and x.get_name() != "Mayo" and x.get_name() != "Ketchup" and x.get_name() != "Laxative" and x.get_name() != "Exercise":
			current_largest = x;

	if current_largest.get_name() == "null":
		hand.remove(hand[0])
		ai_card = cards.card("Patty", 1)
	else:	
		hand.remove(current_largest)
		ai_card = current_largest
	hand, deck = add_cards(hand, deck)
	ai_card_choice = []
	ai_card_choice.append(ai_card.get_name().lower())
	return ai_card_choice, hand, deck
Example #10
0
 def test_user_wins_with_blackjack(self):
     """
     Test that the user wins when they get blackjack and they get the custom message
     """
     test_shoe = self.test_shoe
     player_list = self.test_player_list
     dealer = self.dealer
     player = player_list[0]
     test_shoe.cards.insert(0, card(10, "H"))
     test_shoe.cards.insert(2, card(1, "H"))
     initial_deal(test_shoe, player_list, dealer)
     self.assertEqual(player.get_score(), 21)
     self.assertTrue(check_blackjack(player.get_score(), player.get_hand()))
     dealer_play(test_shoe, dealer)
     results = check_results(player_list, dealer)
     blackjack_winners = results[3]
     self.assertIn(player, blackjack_winners)
Example #11
0
 def test_user_pushes_with_blackjack(self):
     """
     Test that the user pushes with blackjack when the dealer also has a blackjack
     """
     test_shoe = self.test_shoe
     player_list = self.test_player_list
     dealer = self.dealer
     player = player_list[0]
     test_shoe.cards.insert(0, card(10, "H"))
     test_shoe.cards.insert(1, card(10, "C"))
     test_shoe.cards.insert(2, card(1, "H"))
     initial_deal(test_shoe, player_list, dealer)
     self.assertEqual(player.get_score(), 21)
     dealer_play(test_shoe, dealer)
     self.assertTrue(check_blackjack(dealer.get_score(), dealer.get_hand()))
     self.assertTrue(check_blackjack(player.get_score(), player.get_hand()))
     results = check_results(player_list, dealer)
     pushers = results[2]
     self.assertIn(player, pushers)
Example #12
0
 def test_user_loses(self):
     """
     Test that a user loses when the dealer's score exceeds theirs and the dealer doesn't bust
     """
     test_shoe = self.test_shoe
     player_list = self.test_player_list
     dealer = self.dealer
     player = player_list[0]
     test_shoe.cards.insert(0, card(8, "H"))
     test_shoe.cards.insert(1, card(10, "C"))
     test_shoe.cards.insert(2, card(8, "C"))
     test_shoe.cards.insert(3, card(6, "D"))
     initial_deal(test_shoe, player_list, dealer)
     dealer_play(test_shoe, dealer)
     self.assertLess(player.get_score(), dealer.get_score())
     self.assertFalse(check_blackjack(player.get_score(),
                                      player.get_hand()))
     results = check_results(player_list, dealer)
     losers = results[1]
     self.assertIn(player, losers)
Example #13
0
 def test_user_pushes(self):
     """
     Test that when a user's score and the dealer's score are the same they push
     """
     test_shoe = self.test_shoe
     player_list = self.test_player_list
     dealer = self.dealer
     player = player_list[0]
     test_shoe.cards.insert(0, card(8, "H"))
     test_shoe.cards.insert(1, card(10, "C"))
     test_shoe.cards.insert(2, card(9, "C"))
     test_shoe.cards.insert(3, card(6, "D"))
     initial_deal(test_shoe, player_list, dealer)
     dealer_play(test_shoe, dealer)
     self.assertEqual(player.get_score(), dealer.get_score())
     self.assertFalse(check_blackjack(player.get_score(),
                                      player.get_hand()))
     results = check_results(player_list, dealer)
     pushers = results[2]
     self.assertIn(player, pushers)
Example #14
0
 def test_user_wins_when_dealer_busts(self):
     """
     Test that a user wins when the dealer exceeds 21 as long as they have not also bust themselves
     """
     test_shoe = self.test_shoe
     player_list = self.test_player_list
     dealer = self.dealer
     player = player_list[0]
     test_shoe.cards.insert(0, card(8, "H"))
     test_shoe.cards.insert(1, card(10, "C"))
     test_shoe.cards.insert(2, card(8, "C"))
     test_shoe.cards.insert(3, card(6, "D"))
     test_shoe.cards.insert(4, card(10, "D"))
     initial_deal(test_shoe, player_list, dealer)
     dealer_play(test_shoe, dealer)
     self.assertTrue(dealer.check_bust())
     self.assertFalse(check_blackjack(player.get_score(),
                                      player.get_hand()))
     results = check_results(player_list, dealer)
     winners = results[0]
     self.assertIn(player, winners)
Example #15
0
def print_cards(cards, path):
    empty_card = card('', '')
    env = Environment(loader=FileSystemLoader('.'))
    template = env.get_template(args.template)

    html = template.render({
        'cards': cards,
        'empty_card': empty_card,
        'horizontal': args.horizontal
    })
    with open(path, 'w') as f:
        f.write(html)
Example #16
0
from cards import card  ##import the model

deck = []
for suit in range(1, 5):
    for rank in range(1, 14):
        deck.append(card(suit, rank))
hand = []
for i in range(0, 5):
    a = random.choice(deck)
    hand.append(a)
    deck.remove(a)
Example #17
0
 def dealCard_(deck, f, wantedValue):
     if wantedValue is None:
         f(deck.dealone())
     else:
         f(cards.card(wantedValue, 0))
Example #18
0
                    default=1000,
                    help="How many cards to print in one html files")
args = parser.parse_args()

# 1. Loads list of ids(secret_id, public_id) from json file
# 2. each 'ids', generate QR code using 'secret_id' and make a 'card' object
# 3. write HTML file using Jinja2 template

with open(args.input, 'r') as f:
    id_pairs = json.load(f)

cards = []
for id_pair in id_pairs:
    qr = gen_qr_code(args.base_url, id_pair['secret_id'])

    newcard = card(qr, id_pair['public_id'])
    cards.append(newcard)


def print_cards(cards, path):
    empty_card = card('', '')
    env = Environment(loader=FileSystemLoader('.'))
    template = env.get_template(args.template)

    html = template.render({
        'cards': cards,
        'empty_card': empty_card,
        'horizontal': args.horizontal
    })
    with open(path, 'w') as f:
        f.write(html)
Example #19
0
 def __cleandeck__(self):
     d = []
     for a in cards.SUITS:
         for b in cards.CARDS:
             d.append(cards.card(a, b))
     return d
Example #20
0
 def __cleandeck__(self):
     d = []
     for a in cards.SUITS:
         for b in cards.CARDS:
             d.append(cards.card(a, b))
     return d
        positions_list.append(current_pos)
        print("current position: " + monopoly_board[current_pos])
        landings_counter[current_pos] += 1
        if i > 1 and dice.go_to_jail(i, current_pos, doubles_list[-1],
                                     doubles_list[-2], doubles_list[-3]):
            print("GO TO JAIL!")
            if positions_list[-1] != 30:
                positions_list = positions_list[:-1]
                landings_counter[current_pos] -= 1
            current_pos = 10
            print("current position: " + monopoly_board[current_pos])
            positions_list.append(current_pos)
            landings_counter[current_pos] += 1
        elif "cc" in monopoly_board[current_pos]:
            print("DRAW COMMUNITY CHEST CARD!")
            cc_card = card("cc", current_pos)
            #print("Do we need to move? " + str(cc_card.advance_to != current_pos))
            if cc_card.advance_to != current_pos:
                current_pos = cc_card.advance_to
                positions_list.append(current_pos)
            print("current position: " + monopoly_board[current_pos])
        elif "chance" in monopoly_board[current_pos]:
            print("DRAW CHANCE CARD!")
            chance_card = card("chance", current_pos)
            #print("Do we need to move? " + str(chance_card.advance_to != current_pos))
            if chance_card.advance_to != current_pos:
                current_pos = chance_card.advance_to
                positions_list.append(current_pos)
            print("current position: " + monopoly_board[current_pos])
        print("_________________________________________")
else:
Example #22
0
 def test_cut_card(self):
     """
     Test that a cut card is added to the deck
     """
     self.assertEqual(card("cut").get_card_details(), "cutcut")