Blackjack In Python

$ begingroup $ I think you really need to read the documentation on how classes in python work. For example, you would rarely ever have free standing code as seen in the Deck class, you would either put it in the init function or under a different function $ endgroup $ – Navidad20 Dec 14 '16 at 18:26. I am currently learning Python through a course on Udemy and I'm working on a milestone project to create a Blackjack game. The only rule is for me to use Object Oriented Programming and to create classes for things like the Card and Deck. Documentation of the BlackJack Game¶. Here is a little bit of documentation about the more important functions and classes from the blackjack program. This documentation is auto-generated from the Python source code and doc strings contained in. Blackjack is a simple, popular card game that is played in many casinos. Cards in Blackjack have the following values: an ace may be valued as either 1 or 11 (player's choice), face cards (kings, queens and jacks) are valued at 10 and the value of the remaining cards corresponds to their number. I've only been learning Python for a few days after a Humble Bundle book sale, but I made a functional Blackjack game on which I'd like some constructive criticism as far as my coding structure and any suggestions for improvement from more experienced coders. Edit: This is coded in Python 3.8.2.

Latest version

Released:

Red-black trees

Blackjack Python 3 Code

Project description

Blackjack is a simple implementation of the classic red-black tree as astandard Python data structure. A set and a dictionary are included:

Blackjack

Usage

Blackjacks and decks behave just like normal Python sets and dictionaries, buthave different performance characteristics and different requirements forkeys. All keys must be comparable, but need not be hashable:

This does impact heterogeneity somewhat, but shouldn’t be a problem for mostcommon uses. On the other hand, the average and worst-case times for access,membership testing, insertion, and deletion are all logarithmic, which makesblackjacks ideal for storing mappings of data with untrusted keys:

Even on small- to medium-sized sets of data, blackjacks quickly become moreeffective than dictionaries in the face of untrusted input.

This package only contains the blackjack module; tests are in the moduleand may be run with any standard test runner:

Technical information

The specific trees used are left-leaning red-black trees. Red children areopportunistically reduced during balancing if nodes will be recreated anyway;this tends to shorten overall tree height by reducing the number of redchildren. Complexities are as follows:

OperationTimeSpace
LookupO(log n)O(1)
MembershipO(log n)O(1)
InsertionO(log n)O(log n)
DeletionO(log n)O(log n)
UpdateO(log n)O(log n)
SortO(1)O(1)
LengthO(1)O(1)

Sorting according to the provided key function is constant because the tree’straversal order is presorted. Length is recorded and updated on mutation.Nodes are persistent and altering the tree generally requires a logarithmicspace commitment to create new nodes.

Release historyRelease notifications RSS feed

1.1.1

1.1

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for blackjack, version 1.1.1
Filename, sizeFile typePython versionUpload dateHashes
Filename, size blackjack-1.1.1.tar.gz (6.2 kB) File type Source Python version None Upload dateHashes

Blackjack Python Simulator

Close

Hashes for blackjack-1.1.1.tar.gz

Hashes for blackjack-1.1.1.tar.gz
AlgorithmHash digest
SHA2569b709b61fc2888f3ab76231c78c1e1642e89f4c67a3e2629481680a8100801e0
MD5f6ab60d22e93f1d60a8f75688380c91a
BLAKE2-256bf36fcfea476d0def0fb62d4d65646d4ac6898381018aa99fc847f5cd44a5bc9

In this challenge you are going to create a blackjack game for one player. The computer will be the dealer.

Rules of the game


Source: wikipedia.

“Blackjack, also known as twenty-one, is the most widely played casino banking game in the world. Blackjack is a comparing card game between a player and dealer, meaning that players compete against the dealer but not against any other players. It is played with one or more decks of 52 cards. The object of the game is to beat the dealer, which can be done in a number of ways:

  • Get 21 points on the player’s first two cards (called a blackjack), without a dealer blackjack;
  • Reach a final score higher than the dealer without exceeding 21; or
  • Let the dealer draw additional cards until his or her hand exceeds 21.

The player or players are dealt an initial two-card hand and add together the value of their cards. Face cards (kings, queens, and jacks) are counted as ten points. A player and the dealer can count his or her own ace as 1 point or 11 points. All other cards are counted as the numeric value shown on the card. After receiving their initial two cards, players have the option of getting a “hit”, or taking an additional card. In a given round, the player or the dealer wins by having a score of 21 or by having the highest score that is less than 21. Scoring higher than 21 (called “busting” or “going bust”) results in a loss. A player may win by having any final score equal to or less than 21 if the dealer busts. If a player holds an ace valued as 11, the hand is called “soft”, meaning that the player cannot go bust by taking an additional card; 11 plus the value of any other card will always be less than or equal to 21. Otherwise, the hand is “hard”.

The dealer has to take hits until his or her cards total 17 or more points. (In some casinos the dealer also hits on a “soft” 17, e.g. an initial ace and six.) Players win if they do not bust and have a total that is higher than the dealer’s. The dealer loses if he or she busts or has a lesser hand than the player who has not busted. If the player and dealer have the same total, this is called a “push” and the player typically does not win or lose money on that hand.”

Final Product


Blackjack in python codeYou can check this game online.

Your Challenge


Your challenge is to recreate this game for one player only using your chosen programming language (e.g. Python, JavaScript…). The end-user will play against the computer (the dealer).

To start with you may want to create this game using a text-based interface. Cards could be displayed as follows:

  • ♠ As (Ace of spade), 2s, 3s, … 9s, 10s, Js, Qs, Ks
  • ♥ Ah (Ace of heart), 2h, 3h, … 9h, 10h, Jh, Qh, Kh
  • ♣ Ac (Ace of club), 2c, 3c, … 9c, 10c, Jc, Qc, Kc
  • ♦ Ad (Ace of diamond), 2d, 3d, … 9d, 10d, Jd, Qd, Kd

You may also want to investigate unicode charactersSlot gold wings. to display the selected cards in a more visual way.

Tips / Questions to get you started


Before getting started you may want to ask yourself the following questions?
  • What data structure could I use to create the deck of 52 cards?
  • Once I have stored all 52 cards in my data structure, how can I shuffle the cards?
  • What variables will I need to store the initial amount ($) the player has, the value of the bet ($), the total number of points of the dealer, the total number of points for the player?
  • Input: What information do I need to ask/retrieve from the end-user and when does the program need to ask for that information?
  • Output: What information do I need to display to the end-user during the game? (and when in the game?)
  • When or how does the game end?
  • How can I break up this project into smaller achievable steps? What would be the first few steps that I would then focus on?

Complete the Code…


Graphical User interface


Should you decide to create a full graphical user interface (e.g. as a webpage using HTML & JavaScript or as a Python program using graphical library such as PyGame) then you can download the graphics for each of the playing cards from wikimedia.

Other challenges you may enjoy..

Tagged with: iteration, List, Selection