Skip to content
A typical one-player implementation of the card game Blackjack
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
design
src
test
.gitignore
Blackjack.iml
Readme.md
build.xml
manifest.mf

Readme.md

Vision Statement

This Blackjack game allows a player to play a game of Blackjack according to common casino rules. A typical one-player implementation.

What are the rules?

The main goal of Blackjack is to collect a hand of cards whose value is greater than that of the dealer’s hand without exceeding 21.

  • The player makes a bet.
  • The player is dealt two cards, face up usually. The dealer is also dealt two cards, usually one up (exposed) and one down (hidden).
  • Cards are valued as following:
    • Cards 2 through 10 have a value the same as their rank;
    • Face cards (Jack, Queen, and King) are all worth 10;
    • Aces can be worth 1 or 11.
  • A hands's value is the sum of the card values. The soft value is where an Ace is 11 and another card can be added without exceeding 21, the hard value is where an Ace is valued as 1.
  • Players have the following decision on their turn:
    • Hit: Take another card from the dealer.
    • Stand: Take no more cards.
    • Double down: After being dealt the initial 2 cards, the player is allowed to increase the initial bet by 100% in exchange for committing to stand after receiving exactly one more card. The additional bet is placed in the betting box next to the original bet.
    • Split: If the first two cards of a hands have the same value, the player can split them into two hands, by moving a second bet equal to the first into an area outside the betting box. The dealer separates the two cards and draws an additional card on each, placing one bet with each hands. The player then plays out the two separate hands in turn; except for a few restrictions, the hands are treated as independent new hands, with the player winning or losing their wager separately for each hands. Doubling and further splitting of post-split hands may be restricted, and an ace and ten value card after a split are counted as a non-blackjack 21. Hitting split aces is usually not allowed.
  • The dealer hands will not be completed if the player has busted or received a blackjack.
  • The dealer must hit until the cards total 17 or more points (including soft 17).
  • The player wins by not busting and having a total higher than the dealer, or getting a blackjack without the dealer getting a blackjack. If the player and dealer have the same total (not counting blackjacks), this is called a "push", and the player typically does not win or lose money on that hands.
  • The player is paid out as follows:
    • a blackjack (first 2 cards = 21) is paid at 1.5 x bet (and the bet is returned)
    • a victory is paid at 1 x bet (and the bet is returned)
    • a draw returns the bet

Different versions

I have developed a few versions for teaching/learning which are organised into the following packages (with matching test suites in test folder):

procedural

This is the simplest implementation in a single class. The players moves are "hit" and "stand". A single deck is used. The user interface is the console.

The following topics need to covered to complete/understand this:

  1. variables and datatypes
  2. control statements (if)
  3. loops (while, for)
  4. Scanner class
  5. Strings and StringBuilder (and their methods)
  6. Arrays
  7. Methods (return types, parameters, static)

intermediate

This is the simplest object-orientated implementation. The players moves are "hit" and "stand". A single deck is used. The user interface is the console.

The following topics need to covered to complete/understand this:

  1. variables and datatypes
  2. control statements (if)
  3. loops (while, for)
  4. Scanner class
  5. Strings and StringBuilder (and their methods)
  6. Arrays
  7. Methods (return types, parameters)
  8. Basic object-orientated design
  9. Classes (instance variables and methods)
  10. Object creation (reference variables)

advanced (IN PROGRESS)

This is a more advanced "ideal" object-orientated implementation. The players moves are "hit", "stand", "double down", and "split". 8 decks are used. The user interface is the console.

The following topics need to covered to complete/understand this:

  1. variables and datatypes
  2. control statements (if)
  3. loops (while, for)
  4. Scanner class
  5. Strings and StringBuilder
  6. Arrays
  7. Methods (return types, parameters)
  8. Basic object-orientated design
  9. Classes (instance variables and methods)
  10. Object creation (reference variables)
  11. enums
  12. List (ArrayList)
  13. Collections class
  14. Exceptions

advanced-gui (NOT DONE)

This is the same as the advanced, except the user interface is a Java windowed interface.

advanced-web (NOT DONE)

This is the same as the advanced, except the user interface is a web page.

advanced-android (NOT DONE)

This is the same as the advanced, except it is an android app.

You can’t perform that action at this time.