Example #1
0
def testLoadCards():
    cl.Deck.setValuesRange()
    print(cl.Deck.valuesSkills)    
    deck = cl.Deck(cl.Deck.MIN_NO_CARDS)
    deck.loadCards()
    deck.suffleDeck()
    deck.showDeck()
    print(cl.Deck.valuesSkills)    
    deck2 = cl.Deck(cl.Deck.MIN_NO_CARDS)
    deck2.loadCards()
    deck2.suffleDeck()
    deck2.showDeck()
    print(cl.Deck.valuesSkills)
 def test_deal(self):
     deck = classes.Deck()
     card1 = deck.deal()
     card2 = deck.deal()
     card3 = deck.deal()
     self.assertIsInstance(card1, classes.Card)
     self.assertIsInstance(card1, object)
     self.assertIsInstance(card2, classes.Card)
     self.assertIsInstance(card2, object)
     self.assertIsInstance(card3, classes.Card)
     self.assertIsInstance(card3, object)
    def setUp(self):
        self.deck = classes.Deck()
        self.deck.shuffle()
        self.players_hand = classes.Hand('player')
        self.dealers_hand = classes.Hand('dealer')
        self.players_hand.draw_card(self.deck.deal())
        self.players_hand.draw_card(self.deck.deal())
        utils.first_hand(self.players_hand, self.dealers_hand)
        utils.play_hand(self.deck, self.players_hand)
        utils.dealer_sim(self.deck, self.players_hand, self.dealers_hand)
        utils.reset_deck(self.players_hand, self.dealers_hand)



        self.card1 = classes.Card("\u2663", "7")
        self.card2 = classes.Card("\u2665", "J")
        self.card3 = classes.Card("\u2666", "3")
        self.card4 = classes.Card("\u2660", "5")
        self.card5 = classes.Card("\u2666", "A")
        self.card6 = classes.Card("\u2663", "Q")
        
        text_trap = io.StringIO()
        sys.stdout = text_trap
Example #4
0
def main():
    deck = classes.Deck()
Example #5
0
def get_deck():
    deck = c.Deck()
    deck.make_cards()
    deck.shuffle()
    return deck
Example #6
0
def main():
    global playing
    print("Welcome to Blackjack")

    player_name = input("What's your name? ")
    player_hand = classes.Hand(player_name)
    dealer_hand = classes.Hand("dealer")

    while True:
        try:
            player_total = int(input("How much are you bringing to the table? "))
            player_chips = classes.Chips(player_total)
            break
        except:
            print("We are sorry, this is an inappropriate value for your chips.")

    while True:
        deck = classes.Deck()
        deck.shuffle()

        functions.take_bet(player_chips)
        print("\n")

        player_hand.add_card(deck.deal())
        player_hand.add_card(deck.deal())

        dealer_hand.add_card(deck.deal())
        dealer_hand.add_card(deck.deal())

        functions.show_some(player_hand, dealer_hand)
        while playing:
            playing = functions.player_action(deck, player_hand)
            print("\n")
            functions.show_some(player_hand, dealer_hand)

            if player_hand.value > 21:
                functions.player_busts(player_hand, dealer_hand, player_chips)
                break
            


        if player_hand.value <= 21:
            functions.show_all(player_hand, dealer_hand)
            input("Press Enter to Continue ...")

            if dealer_hand.value < 17:
                print("The dealer has elected to hit:")
                dealer_hand.add_card(deck.deal())
                functions.show_all(player_hand, dealer_hand)
                input("Press Enter to Continue ...")

            if dealer_hand.value > 21:
                functions.dealer_busts(player_hand, dealer_hand, player_chips)

            elif dealer_hand.value > player_hand.value:
                functions.dealer_wins(player_hand, dealer_hand, player_chips)

            elif dealer_hand.value == player_hand.value:
                functions.push(player_hand, dealer_hand, player_chips)

            else:
                functions.player_wins(player_hand, dealer_hand, player_chips)

        if player_chips.total == 0:
            print("You have no more chips to play with, thank you for playing.")
            break

        action = input("Do you wish to play again? (y/n) ")

        if action[0].lower() == "n":
            break

        player_hand.clean_hand()
        dealer_hand.clean_hand()
        playing = True
import classes
import time

deck = classes.Deck()


def first_deal() -> list:
    # This function picks out 4 random cards for Deck class and puts them in two sets and returns the two sets as a list
    # This function serves as a original deal to two players
    a = deck.deal()
    b = deck.deal()
    c = deck.deal()
    d = deck.deal()
    set_a = (a, c)
    set_b = (b, d)
    lst = [set_a, set_b]
    return lst


def hit_or_stand_q() -> str:
    # This function works as a repeating question until they supply either hit or stand
    x = input("Hit or Stand\n").lower()
    if x == "hit":
        return x
    elif x == "stand":
        return x
    else:
        print("Try again")
        hit_or_stand_q()

 def test__deck(self):
     deck = classes.Deck()
     self.assertIsInstance(self.deck, classes.Deck)
     self.assertIsInstance(self.deck, object)
Example #9
0
 def __init__(self):
     self.deck = classes.Deck()
     self.hands = [self.deck.deal(), self.deck.deal()]
     self.player = self.hands[0]
     self.dealer = self.hands[1]
Example #10
0
def game():
    clear()
    print("Hello Player!")
    print("Welcome to blacjack!")

    player = cl.Player()
    computer = cl.Computer()
    deck = cl.Deck()
    board = cl.Board()

    while True:
        #new game
        player.new_game()
        computer.new_game()

        #Player give a bet
        print(f"Your credits equals {player.money}$")
        board.bet = player.bet()
        game_continue()
        clear()
        deck.shuffle()

        #Players takes cards
        for i in range(0, 2):
            player.take_card(deck.pop_card())
            computer.take_card(deck.pop_card())

        #lambda expressions
        value_player = lambda: deck.player_value(player.hand)
        value_computer_one = lambda: deck.player_value([computer.hand[0]])
        value_computer = lambda: deck.player_value(computer.hand)

        board_print_one_card = lambda: board.table_one_card(
            player.hand, value_player(), computer.hand, value_computer_one())
        board_print_all_cards = lambda: board.table_all_card(
            player.hand, value_player(), computer.hand, value_computer())

        #Printing first board
        board_print_one_card()

        #True if BUST
        bust = lambda a: board.do_bust(deck.player_value(a))

        #Hit or Stand while not BUST or Stand
        while not bust(player.hand) and player.hit_or_stand():
            player.take_card(deck.pop_card())
            board_print_one_card()

        #Computer takes cards if player not bust and has less points than player
        if not bust(player.hand):
            while value_computer() < value_player():
                computer.take_card(deck.pop_card())

        board_print_all_cards()

        #checking who win
        if bust(player.hand):
            print("Player BUST")
            print("Computer WINS")
        elif bust(computer.hand):
            print("Computer BUST")
            print("Player WINS")
            player.money += 2 * board.bet
        elif value_player() > value_computer():
            print("Player WINS")
            player.money += 2 * board.bet
        elif value_player() == value_computer():
            print("DRAW")
            player.money += board.bet
        else:
            print("Computer WINS")

        #does player have any money?
        if player.money == 0:
            print("You are out of cash!")

        #pleyer out of money or wants to end the game
        if player.money == 0 or end_of_game():
            print("Thank you for game!")
            if player.money != 0:
                print(f"Your credits equals {player.money}$")
            break
        else:
            clear()
Example #11
0
				elif formato == 3:
					formato_deck = 'COMMANDER'
					break
				elif formato == 4:
					formato_deck = 'PAUPER'
					break
				elif formato == 5:
					formato_deck = 'LEGACY'
					break
				elif formato == 6:
					formato_deck = 'VINTAGE'
					break
				else:
					"Resposta invalida!\n"	
			
			deck = classes.Deck(nome_deck, formato_deck, nick)
			deck.novo_deck()
			opcao_exclui = 0
			pass

		elif resposta == 2:
			#edita_deck/////////////////
			nome_edita = raw_input("Qual o nome do deck que deseja editar:\n")
				
			while(edita_deck > 6 or edita_deck < 1):
				edita_deck = input("Qual o formato do deck que deseja editar:\n1) STANDART(T2);\n2) MODERN;\n3) COMMANDER;\n4) PAUPER;\n5) LEGACY;\n6) VINTAGE.\n")
				if edita_deck == 1:
					formato_edita = 'STANDART(T2)'
					break
				elif edita_deck == 2:
					formato_edita = 'MODERN'