Skip to content

An implementation of the Classic BlackJack Game using the State and Factory Design Pattern

Notifications You must be signed in to change notification settings

srijitravi94/BlackJack-State-Pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Implementation of BlackJack using State Pattern and Factory Pattern

This repository is a terminal application of the classic gambling game called BlackJack a.k.a Twenty-One. BlackJack is a comparing card game between usually several players and a dealer, where each player in turn competes against the dealer, but players do not play against each other. It is played with one or more decks of 52 cards, and is the most widely played casino banking game in the world. The objective of the game is to beat the dealer in one of the following ways:

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

    The Basic Strategy for a player to take decision based on the hand. For convenience Double is not implemented. BlackJack Basic Strategy

The implementation does not have any user interface and the main objective is to accomplish the game of BlackJack to use State Design Pattern and Factory Design Pattern. The state design pattern is the best choice to implement BlackJack since the game has finite number of states. This game is played with a standard 6 decks of 52 cards each. Additionally, the game is implemented to accommodate any number of decks and any number of players. The major state changes occur in GameClass.java where the method play() handles the state behaviour of the players and the dealer. The factory pattern is implemented in GameFactory.java. The factory pattern was used to create specialized versions of the game by creating subclasses of GameClass.

Various states employed to implement the game of BlackJack are :

  • Start Game State : Sets the state of play to Start State for a specified player.

  • Player Turn State : Sets the state to Player Turn State for a specified player. Player can either hit or stand based on the combinations mentioned in the chart.

  • End Round State : Sets the state of the specified player to End Round State. The player can no longer hit the deck of cards after this state. The player may either be busted or in Stand state.

  • Dealer Turn State : Sets the Dealer Turn State to all the players. After all the players have either decided to stand or if the players are busted, dealer now starts to play.

After all the states are completed, based on evaluating dealer's sum of cards, winners are evaluated and the winning amount is distributed to the players.

About

An implementation of the Classic BlackJack Game using the State and Factory Design Pattern

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages