Game 1: Blackjack

Software description

  1. Variables

Load = loads and stores the file cardDeck.mat to the program

fullDeck = defines full deck for all numbers from 1-52 assigning each card a number

cardsLeft = gives the initial cards left which is the full deck (52) and decreases each time you ask for a card

playerScore = defines the score goal and

cardNum = each player starts with one card given and then can ask for another card as the game goes on or until the go over 21.

playerTurn = while true this statement will always rerun the program

draw = chooses a random number from the deck for the player and then subtracts that card using cardleft – 1

playerCard = creates a sequence for when to give a player a new card or determine if they went over 21

deck1= uses imshow to show the deck player 1 has.

Acescore = allows the user to either assign an ace to a 1 or 11

  1. Commands

While = keeps the game running when playerTrue is true or when the user asks for another card until they bust

Also, it used to ask the user to assign an Ace a value if they have one

If and elseif = combination of statements to determine If the player has gone over 21 or to ask if they want a new card

Also used to ask the user to assign the Ace a value and then display the value selected

Figure(1) = opens a figure window of the hand

disp = displays what is in ()

fprintf = displays what is inside the () and shows numbers of the variable

  1. Ensure that there is only four of each value in the deck
  2. Shuffle the deck of cards
  3. Deal two cards to the players and dealer
  4. Read dealt cards
  5. Dealer reveals his first card
  6. Ask the players to draw or hold
  7. If player asks to draw card, proceed to step 8, if not proceed to step 11
  8. Dealer deals card to player
  9. If player’s hand is greater than 21, go to step 16, if not proceed to step 10
  10. If player’s hand is lower than 21, return to step 6, if not go to step 17
  11. If dealer’s hand is lower than 16, then he draws a card
  12. Dealer holds if hand greater than 16 and less than 21, if less than 16, go back to step 11
  13. Reveal all cards
  14. If dealer’s hand exceeds 21, go to step 17
  15. If player’s hand is bigger than dealer’s hand go to step 17, if not go to step 16
  16. You lose
  17. You win

Intro to Blackjack:

Blackjack is a common casino card game usually played with 2 different people. The game’s main objective is to get a total of 21 points (or as close to 21 points without going over it), with the fact that the cards are worth their face values and special cards are worth 10. The first player receives a card, and he decides whether or not to receive another, until he wants to stop (or surpasses 21). The same procedure is used for the second player and then the winner is decided based on whoever is closer to 21 (as long as they are below it).

User Manual

To win the game, you want to get a score of 21 with the cards in your hand, or come as close to it as possible without going over while maintaining a higher score than your opponents.

1) The player receives a card

2) If the player receives an ace, the player decides if it is valued as a 1 or an 11.

3) The player decides either to receive or not receive a card. To receive the player presses Y, to not, the player presses N

4) The first 3 steps are repeated unless the user pressed N, or the player has over 21 points

5) The second player’s turn starts

6) The first 4 steps repeat for the second player

7) The winner is decided by the computer, and the players have to press any button to stop the program.

8) The winner is decided by whichever player has the higher score. If both players have the same score, or if both players bust, then it is a tie.

Discussion Blackjack:

The code starts off by printing some explanations for the player to read using the ‘fprintf’ command. Then it uses a while loop with if statements to evaluate commands such as ‘hold’ or ‘draw’. It also uses said loop and if statements to calculate the players points. When the first player is done, it then progresses over to the next player and does the same thing. When both players have finished their turns the code then announces the winner. It then closes the program. The main difficulty that was encountered during the writing of this code was the Aces’ value. The code couldn’t detect and assign the ace the correct value (11 or 1). This issue was resolved by making the user manually type the value when and if the ace is received. To ensure the players’ benefit, the player could change the value of the ace each round.

Conclusions and Recommendations Blackjack:

This game is very good compared to most other blackjack games on the market, its only major fault is that it requests user input for aces instead of auto-detection. If this game is being considered for release, the game needs the ace auto detection feature. A minor fault is that this game has no ‘Play

again’ feature, but this can be easily resolved and shouldn’t pose a problem. In conclusion, the coding and the usage of while loops and if statements were used well, but some more inputs are needed.