Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


Blackjack en Python instrucciones, Ejercicios de Tecnología

Estas son las instrucciones para que resuelvas un blackjack en python

Tipo: Ejercicios

2022/2023

Subido el 19/08/2023

alejandro-benavides-rubio
alejandro-benavides-rubio 🇨🇴

2 documentos

1 / 10

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
FUNDAMENTALS OF PROGRAMMING - FINAL
PROJECT
First, congratulations on completing the course! This will be a chance for you
to apply the skills you’ve learned throughout the course and get some
valuable feedback from me. The game you will work to create is Blackjack!
If you need a refresher on the rules you can read up here or read the short
descriptions of the game provided below.
THE GAME OF BLACKJACK
Description: Blackjack is a very popular gambling game, typically played in
casinos. It involves a dealer and between 1-6 other players. For our purposes
we will be playing a version of blackjack that involves one player and a
dealer.
Objective: Each player at the table plays alone and soles objective is to
have a higher hand than the dealer without going over 21. Normally bets are
placed before the round starts and each player that wins will have their bet
matched by the dealer. If the player loses then the dealer will take their bet.
For this version of the game we will not play with bets.
Game Play: The game may contain infinite rounds. Each round starts with
the dealer and each player being dealt two cards. The players cards are
dealt faceup and the dealer is dealt one card face down and one face up. The
player will look at their cards and choose one of two options: HIT or STAY. If
the player decides to HIT, they will be given another card. If the player
decides to STAY, the next player on the table will go. A player may HIT as
many times as they like. However, if the value of their cards sums to greater
than 21, they BUST and will loose the round. Once each player has gone the
dealer will flip over their hidden card. They will then follow a set of
predefined rules on whether to HIT or STAY. At the end of the dealers turn
they will compare their hand to each player. If they have a higher hand and
have not gone over 21 that player will loose. If the dealer has a lower hand
or went over 21 then that player will win. The cards will then be reshuffled,
and a new round will begin.
Dealer Rules: If the value of the dealer’s cards is below 17, they must HIT,
otherwise they must STAY. The dealer will HIT as many times as necessary.
Card Values:
pf3
pf4
pf5
pf8
pf9
pfa

Vista previa parcial del texto

¡Descarga Blackjack en Python instrucciones y más Ejercicios en PDF de Tecnología solo en Docsity!

FUNDAMENTALS OF PROGRAMMING - FINAL

PROJECT

First, congratulations on completing the course! This will be a chance for you to apply the skills you’ve learned throughout the course and get some valuable feedback from me. The game you will work to create is Blackjack! If you need a refresher on the rules you can read up here or read the short descriptions of the game provided below.

THE GAME OF BLACKJACK

Description: Blackjack is a very popular gambling game, typically played in casinos. It involves a dealer and between 1-6 other players. For our purposes we will be playing a version of blackjack that involves one player and a dealer. Objective: Each player at the table plays alone and soles objective is to have a higher hand than the dealer without going over 21. Normally bets are placed before the round starts and each player that wins will have their bet matched by the dealer. If the player loses then the dealer will take their bet. For this version of the game we will not play with bets. Game Play: The game may contain infinite rounds. Each round starts with the dealer and each player being dealt two cards. The players cards are dealt faceup and the dealer is dealt one card face down and one face up. The player will look at their cards and choose one of two options: HIT or STAY. If the player decides to HIT, they will be given another card. If the player decides to STAY, the next player on the table will go. A player may HIT as many times as they like. However, if the value of their cards sums to greater than 21, they BUST and will loose the round. Once each player has gone the dealer will flip over their hidden card. They will then follow a set of predefined rules on whether to HIT or STAY. At the end of the dealers turn they will compare their hand to each player. If they have a higher hand and have not gone over 21 that player will loose. If the dealer has a lower hand or went over 21 then that player will win. The cards will then be reshuffled, and a new round will begin. Dealer Rules: If the value of the dealer’s cards is below 17, they must HIT, otherwise they must STAY. The dealer will HIT as many times as necessary. Card Values:

2 – 10 are valued 2 – 10 accordingly Any face cards ( Jack, Queen, King ) are valued as 10. An Ace may be used as a 1 or an 11 (whichever favours the player/dealer). The Ace may also change values as the turn progresses. For example, you get a 7 and an Ace, your card value may be 8 or 18. If you decide to HIT and receive another 7 your card value will be 15. This is because the ace acts as a one, as if it was 11 you would bust.

OUR RULES

Here are some of the modifications we will use to simplify the game.

  • There will be only one player
  • There will be no betting
  • There is no doubling down or splitting your cards
  • We will use one 52 card deck
  • Each round we will use a new shuffled deck

THE DECK

As listed above the deck for the game will consist of 52 cards. That is 4 suits of 13 cards. To make things simpler we will represent the suits as follows: 1: HEARTS 2: DIMAONDS 3: CLUBS 4: SPADES We will represent the ranks as follows: 01: ACE 02: TWO 03: THREE 04: FOUR 05: FIVE 06: SIX

Please download the starter code from the course website and work from that file. It is highly recommended that you only use code/syntax covered in this course

FUNCTIONS

Please complete all the functions listed below. Note that you may

call any of these functions from inside any of these functions. You

may also create extra functions that are not listed here.

create_deck()

Will create the deck of cards such that there are 4 suits of 13

cards each. This function will return a list of numbers, each

representing a card.

shuffle_deck(deck)

Will shuffle the list of cards given by the parameter deck.

HINT: Trying looking at the shuffle() method from the random

module.

deal_cards(deck, n)

Will return a list of n cards from the deck given. It should take the

cards off the top of the deck (the beginning of the list).

hand_value(hand)

Will calculate and return the value of a hand given a list (hand) of

cards in that hand.

is_over(hand)

Returns True or False representing if a given hand has gone over

compare_hands(hand1, hand2)

Compares two hands (each hand is a list of cards) and determines

which is the winner. Returns 1 if hand1 is the winner and -1 if

hand2 is the winner. If the hands are of same value, then returns

get_hit_or_stay()

Used to get a decision of either HIT or STAY from the player. It

should keep asking them to enter something until it receives a

valid answer. You may return whatever you feel makes sense

from this function.

The main gameplay will be handled from the mainline of the code.

It will be solely up to you on how you want to code this.

Remember you may add your own functions as well

EXAMPLE RUNS

Your codes output should be as similar to this as possible. The following is copied directly from IDLE after running the program a few times. === RESTART: C:\Users\timot\OneDrive\Desktop\Course\blackjack_solutions.py === Welcome to blackjack!


Round 1 has started! The cards have been dealt... Your Cards: 413, 112. Dealers Cards: 112, hidden.

Would you like to play again (Y/N)? n

=== RESTART: C:\Users\timot\OneDrive\Desktop\Course\blackjack_solutions.py === Welcome to blackjack!


Round 1 has started! The cards have been dealt... Your Cards: 105, 308. Dealers Cards: 308, hidden. Your turn has started. Would you like to hit or stay? no Not a valid option, try again. Would you like to hit or stay? yes Not a valid option, try again. Would you like to hit or stay? hit You hit and received the card: 403 Your Cards: 105, 308, 403. Would you like to hit or stay? stay You decided to stay, your turn is over. The dealers turn has started. The dealer reveals their hidden card is a 403 Dealers Cards: 308, 403. The dealer hits and received: 408 The dealer stays.

The dealer has 19 You have 16 You lost to the dealer... Would you like to play again (Y/N)? y


Round 2 has started! The cards have been dealt... Your Cards: 106, 102. Dealers Cards: 102, hidden. Your turn has started. Would you like to hit or stay? hit You hit and received the card: 306 Your Cards: 106, 102, 306. Would you like to hit or stay? hit You hit and received the card: 410 Your Cards: 106, 102, 306, 410. You BUST and have lost this round. Would you like to play again (Y/N)? yes


Round 3 has started! The cards have been dealt... Your Cards: 308, 207.

Would you like to hit or stay? hit You hit and received the card: 312 Your Cards: 202, 210, 401, 312. You BUST and have lost this round. Would you like to play again (Y/N)? n