C. Program Description for Developers

In this document, a developer can find all the information necessary to unpack and understand all the code in the functions and scripts for the game “Blackjack”. The game was created by four engineering students attending The Ohio State University, Jeremiah Ayres, Joshua, Hunter, and Hans. This game was a final project for the class Engineering 1181 written in MatLab. The information within is organized by function starting with the main script. For each function and script, a reader can find all variables and game commands along with a brief description of them.

The main function “BlackJack_Game.m” has 21 variables. All variables are listed below along with a brief description.

  • card_scene
    • Used for the object-oriented programming. This is generated by the SimpleGameEngine to allow the code to receive inputs in the figure from the player using “getKeyboardInput(card_scene)”.
  • dealerHand
    • (String type array) Contains the dealers hand of which each element represents a card in the hand. For example, if the dealer has an ace of clubs and a king of hearts the array would be [“1C”,”KH”]. Notice that all characters are capitalized.
  • dealerScore
    • (Integer) The numeric score of the dealer’s hand. Note if the score is 22 that hand was a blackjack (the hand had a jack and an ace).
  • deck
    • (String type array) A 52 element array that contains all the cards in a deck that have been shuffled by the function shuffleDeck().
  • displayDealerCard2
    • (Boolean) This is used to determine if the dealers second card should be shown when the card_scene in generated. This is false until the played has completed their turn then it is true.
  • lastCardUsed
    • (Integer) This is used to determine the last index used in “deck” that way when a card is dealt the same card does not get dealt again. This is set to zero after deck is shuffled.
  • playerBet
    • (Integer) A place holder for the initial bet made by the user at the start of each hand. This allows the total bets of hand one and hand two to be incremented by its value. Lastly this is used to determine if the player has enough cash to perform a double down or a split.
  • playerCash
    • (Integer) The total money the player has.
  • playerHand1 and playerHand2
    • (String type array) Contains the player’s hands of which each element represents a card in the hand.
  • playedSecondHand
    • (Boolean) Used to determine if the player played a second hand which will be used to properly score the player vs the dealer and to print the correct prompt to the player at the end of the hand.
  • score1 and score2
    • (Integer) The numeric score of the player’s hand. Note if the score is 22 that hand was a blackjack (the hand had a jack and an ace).
  • temp
    • (Integer) A temporary place holder during an operation.
  • totalBetHand1 and totalBetHand2
    • (Integer) The total bet of the respective hand. This is used to determine the winnings of the player. If the player only won one of that hands then they would only win the amount they bet on that hand.
  • totalWinnings
    • (Integer) Used at the end of the hand to increase playerCash if the player won. If the player lost both hands then this would equal 0.
  • winningsHand1 and winningsHand2
    • (Integer) The output from the score() function which will be added to totalWinnings.
  • x and y
    • (Integer) These are both used to complete an operation based on the players decision. If the value is a 1 the player inputs a yes and the value is a 0 if the player inputs a no.

The function shuffleDeck() creates the deck for the main function shuffles it using a random number generator. This function has no inputs and only on output (deckNew). The following are the 4 variables used for this function along with a brief description.

  • Output
    • deckNew
      • (String type array) A 52 element array of a deck that has been shuffled.
    • Other variables
      • deck
        • (String type array) A 52 element array that contains all the cards in a deck that havent been shuffled.
      • temp
        • (String type array) A 52 element array that receives the shuffled deck.
      • x
        • (Integer type array) A 52 element array of random numbers from 1 to 52. No number is generated twice.

The function split() is used to determine if the player wants to split of not. If they do then it takes the second element of playerHand1 and puts it in playerHand2. Then the function adds on card to the end of playerHand1 and playerHand2. This function has 9 variables and the following is a list of them along with a brief description.

  • Input
    • playerHand1
      • (String type array) Contains the player’s hand of which each element represents a card in the hand.
    • deck
      • (String type array) A 52 element array that contains all the cards in a deck that have been shuffled by the function shuffleDeck().
    • lastCardUsed
      • (Integer) This is used to determine the last index used in “deck” that way when a card is dealt the same card does not get dealt again. This is set to zero after deck is shuffled.
    • playerCash
      • (Integer) The total money the player has.
    • initialBet
      • (Integer) The original bet the player made at the beginning of their turn.
    • card_scene
      • Used for the object-oriented programming. This is generated by the SimpleGameEngine to allow the code to receive inputs in the figure from the player using “getKeyboardInput(card_scene)”.
    • Output
      • playerHand1 and playerHand2
        • (String type array) Contains the player’s hands of which each element represents a card in the hand.
      • lastCardUsed (See above for decription.)
      • playerCash (See above for decription.)
      • totalBetHand2
        • (Integer) The total bet of the second hand
      • Other variables
        • x
          • (Integer) Used to complete an operation based on the players decision. If the value is a 1 the player inputs a yes and the value is a 0 if the player inputs a no.

The yesOrNo() function prompts the user to enter “y” for yes and “n” for no. The input it reads is in the form of “getKeyboardInput(card_scene)”. This means that the input it needs from the player is an input to the figure and not the command line. This function also ensures that the user inputs either a “n” or a “y” and nothing else. It then converts the character into a 1(yes) or 0 (no). This function only requires one input (card_scene) and one output (option). There are 3 variables involved in this function and they are as follows.

  • Input
    • card_scene
      • Used for the object-oriented programming. This is generated by the SimpleGameEngine to allow the code to receive inputs in the figure from the player using “getKeyboardInput(card_scene)”.
    • Output
      • Option
        • (Integer)The numeric decision of the player. If the value is a 1 the player inputs a yes and the value is a 0 if the player inputs a no.
      • Other variables
        • x
        • (char) This is the value of the input from the user. The input is either a “y” for yes or “n” for no.

The blackjack() function checks to see if a hand that the input is a blackjack or not. Blackjack is when a hand has a combination of an ace and a jack of any suit. The function requires that an input of a hand be sent to the function. The output is score. Score will be changed to a 22 if there is a blackjack. If there isn’t a blackjack then the score will be 0. There are 2 variables involved in this function they are as follows.

  • Input
    • hand
      • (String type array) Contains the hand of which each element represents a card in the hand.
    • Output
      • score
        • (Integer) This is used to return a 22 if the hand is a blackjack or a 0 if it isn’t.

The function “bust” checks to see if a hand has busted (exceeded the value 21). If the hand busted then the output is 0, otherwise the output is unchanged. Only one variable is used in this function and it is as follows.

  • Input and Output
    • score
      • (Integer) The numeric score of the hand.

Function dealCards() takes the current deck and deals out two cards. This function is only used in the initial drawl of the cards. There are 2 inputs and 2 outputs. There are 4 variables involved in this function and they are as follows.

  • Inputs:
    • lastCardUsed
      • (Integer) This is used to determine the last index used in “deck” that way when a card is dealt the same card does not get dealt again. This is set to zero after deck is shuffled.
    • deck
      • (String type array) A 52 element array that contains all the cards in a deck.
    • Outputs
      • lastCardUsed (see above)
      • hand
        • (String type array) Contains the hand of which each element represents a card in the hand.

The function dealerTurn() plays the whole dealer turn. It starts by scoring the dealers cards. If the dealers score is under 17 the dealer takes a hit otherwise the dealer stays. This function continues to hit until the score of the dealer’s cards is 17 or greater. There are 7 inputs and 5 outputs. There is a total of 10 variables, they are as follows.

  • Inputs
    • lastCardUsed
      • (Integer) This is used to determine the last index used in “deck” that way when a card is dealt the same card does not get dealt again. This is set to zero after deck is shuffled.
    • Deck
      • (String type array) A 52 element array that contains all the cards in a deck.
    • dealerHand
      • (String type array) Contains the dealer’s hand of which each element represents a card in the hand.
    • playerHand1 and playerHand2
      • (String type array) Contains the player’s hands of which each element represents a card in the hand.
    • displayDealerCard2
      • (Boolean) This is used to determine if the dealers second card should be shown when the card_scene in generated.
    • Outputs
      • lastCardUsed (see above description).
      • deck (see above description).
      • dealerScore
        • (Integer) The numeric score of the dealer’s hand.
      • newDealerHand
        • (String type array) Contains the dealer’s new hand of which each element represents a card in the hand.
      • card_scene
        • Used for the object-oriented programming. This is generated by the SimpleGameEngine to allow the code to receive inputs in the figure from the player using “getKeyboardInput(card_scene)”.
      • Other Variables
        • score
          • (Integer) Temporary place holder for the score of the dealer’s hand.

The function displayCards() is where the graphics are generated using SimpleGameEngine. This function uses 4 inputs and returns 1 output. There are 10 variables in this function and they are as follows.

  • Input
    • playerHand1, playerHand2, and dealerHand
      • (String type array) Contains the hand of which each element represents a card in the hand.
    • displayDealerCard2
      • (Boolean) This is used to determine if the dealers second card should be shown when the card_scene in generated.
    • Output
      • card_scene
        • Used for the object-oriented programming. This is generated by the SimpleGameEngine to allow the code to receive inputs in the figure from the player using “getKeyboardInput(card_scene)”.
      • Other variables
        • bg
          • (Array matrix of Integers) Used to set the background of the game.
        • fg
          • (Array matrix of Integers) Used to set the foreground of the game.
        • y
          • (Array length 2 of Integers) This is used to determine what the size of “bg” should be.
        • i and j
          • (Integers) Used as increment variables for for-loops.

The foreground() function builds the foreground for the graphics. The foreground contains the picture animation of the cards. The function has 3 inputs and 1 output. The function takes the 3 hands for the game, playerHand1, playerHand2, and dealerHand. It looks at each index of each hand and determine the corresponding image for that card. There is a total of 3 variables and they are as follows.

  • Input
    • playerHand1, playerHand2, and dealerHand
      • (String type array) Contains the hand of which each element represents a card in the hand.
    • Output
      • fg
        • (Array matrix of Integers) Used to set the foreground of the game.

The function “bet” allows the player to place an initial bet. The bet must be greater than 0 but less than or equal to 100. First it prompts the player to place a bet then evaluates if the bet is within the parameters previously described. There is one input to the function as well as one output. There is a total of 4 variables used in this function and they are as follows.

  • Input
    • totalCash
      • (Integer) The total money the player has.
    • Output
      • bet
        • (Integer) This variable is what is returned from the function. It is set equal to the playerBet variable. It is the value of the bet made by the player.
      • Other Variables
        • playerBet
          • (Integer) A place holder for the initial bet made by the user at the start of each hand.
        • badBet
          • (Boolean) Set to true initially so that the while loop runs. Then it is used to determine if the player entered a bet where the bet is greater than 0 and less than or equal to 100. When set to false it breaks the loop.

The function score() is used to calculate the change that the player receives if they win. If the player loses the change the player gets is 0 minus the player’s initial bet. There are 3 inputs and 1 output to this function totaling to 4 variables. The variables are as follows.

  • Input
    • playerBet
      • (Integer) A place holder for the initial bet made by the user at the start of each hand.
    • playerScore and dealerScore
      • (Integer) The numeric score of the hand. Note if the score is 22 that hand was a blackjack (the hand had a jack and an ace).
    • Output
      • change
        • (Integer) This is the value of the player’s winnings or lack thereof. If it is negative, then the player loses that money. If it is positive, then the player wins that amount.

The function scoreCards() takes one input and returns one output. The input is a hand array. It uses the hand input to determine the score of the cards. The function looks through each index of the cards and determines the numeric score of each of the cards. It is important to know that the ace is scored last because it can be scored as a 1 or 11. There are a total of 5 variables.

  • Input
    • hand
      • (String type array) Contains the hand of which each element represents a card in the hand.
    • Output
      • finalScore
        • (Integer) This is the returned score of the hand.
      • Other variables
        • score
          • (Integer) This is a temporary place holder for finalScore. The finalScore variable is set equal to score at the end of the function.
        • i
          • (Integer) Used as increment number for a for-loop.
        • numAce
          • (Integer) Used to count how many aces are in the hand. This is important to know so that the code can run the algorithm needed to score the aces.