Blackjack Algorithm:
- Assign a number value to every card in the deck. Then put all of these numbers in a matrix.
- Make sure there are 4 cards with the same number value for each card type of card in the deck and that an ace can be 1 or 11 by user input. All face cards are equal to 10.
- At the start of each new hand, have the cards shuffled.
- Ask the user if they would like to play blackjack.
- Ask the user how much money they would like to bet.
- The dealer AI deals two cards to the player, both face up, and deals two cards to himself, one face up and the other face down.
- If the player has a 10-value card and an ace, the player automatically wins because they got a “blackjack”.
- If their two cards don’t equal 21, ask the player to hit(be given another card) or stay(move on to the dealer’s hand).
- If the player goes over 21, the dealer automatically wins.
- Once the player stays, the dealer must keep hitting until their hand is a greater value than the player’s or until they bust.
- Whoever had the higher hand value that didn’t exceed 21 wins the hand and gets twice the amount of their bet. If the player gets a blackjack, they win the amount they bet plus 1.5x the amount they bet.
- Repeat steps 1-11 until the user decides to stop playing.
- Program the dealer to make logical decisions during the hand so the player will not win every time.
- Have a total win/loss counter and a money earned counter.