C. Program Description for Developers

Black Jack

  1. The program use a while loop to prompt and ask whether the user want to accept the rule and proceed the game.
  2. The program use BlueDeck from the card Deck without jokers.
  3. The program use a new vector ShuffleCard to store the value of the cards in blue deck. Aces are considered as 1 and J.Q,K are all considered as 10
  4. The program generate a vector of random value between 1 to 52 as the index to get cards out from the bluedeck. This this the part to shuffle cards in the game.
  5. The program use figure() function to show the cards to the player and create another image to show one card from the dealer’s hand to the player
  6. The program will access the value in the vector ShuffleCard from the first element in the vector to the last one, and use the value as the index to get card from the bluedeck when hand out cards.
  7. The program will calculate the number of aces and the total value of the cards hold by the dealer(consider aces as 1 at first) .Check how many aces have been considered as 11 and if the value is less than 11 and there are aces in the dealer’s card, add 10 to the total value. If the total value exceed 17, stop getting card from the deck.
  8. The program will prompt and ask the player whether to get another card fro the deck. The system will not bust the player if the player’s value exceed 21. The player should stop whether value of the cards he/she has exceed 21 since he/she already loss. The program will proceed if the user decide not to have another card
  9. The program will calculate whether there are aces in the user’s hand in a for loop and if there are, it will prompt and ask the user whether to consider aces as 11 and how many aces they want to consider as 11.
  10. The program will compare the user’s hand and the player’s hand and find out whether they have busted, wined or lost with if-elseif-else structure and print out the information about the results.

 

Variable list

Variable Name Variable use
C The cell contains all cards
Num_BlueDeck The array stores the value of the cards in BlueDeck in order
ShuffledDeck The array store a random sequence from 1 to 52 as the index of BlueDeck
Play The decision the player made whether to accept the rule and play the game or not
hand1 Array stores the hand of the player
hand2 Array stores the hand of the dealer
card_handout The number of cards that has been hand out
num_hand1 The number of the cards the player has
num_hand2 The number of cards the dealer has
decision The decision player made about whether to have another card
sum_temp Temporary sum of the cards from the dealer to make the decision
num_ace Number of aces the dealer has
DealerFrom1to11 The number of aces that has been considered as 11 in dealer’s hand
sumPlayer The sum of the value of the player’s hand
Player_decision Player’s decision whether to consider an ace as 11
numfrom1to11 The number of aces the player is willing to consider as 11
sumDealer The sum of the value of dealer’s hand
scorePlayer Show how close the sum of value of player’s hand is to 21

scorePlayer=sumPlayer-21

scoreDealer Show how close the sum of value of dealer’s hand is to 21

scoreDealer=sumDealer-21

 

Connect 4

This MATLAB version of Connect 4 utilizes several of MATLAB’s features to allow two users to play Connect 4 by inputting the coordinates of their turn. The program will automatically display the chips however, the users must determine when there is a winner and manually end the game.

A List of All the Variables Used:

  • redchip/blackchip = an image of either a red or black chip
  • Board = a 6 by 7 Connect 4 board
  • player = either 1 or 2, which represents player 1 or 2
  • Player1 and Player2 = a zeros board that is 6 by 7 for each player to store their turns
  • turn = count down how many turns are left from 42 (The amount of spaces in the board)
  • sumPlayer1 and sumPlayer2 = the sum of the zeros board Player1 or Player2
  • I = the row that player 1 (redchip) wants to place a chip in
  • J = the column that player 1 (redchip) wants to place a chip in
  • positionx = I if player 1, x if player 2
  • positiony = J if player 1, y if player 2
  • x = the row that player 2 (blackchip) wants to place a chip in
  • y = the column that player 2 (blackchip) wants to place a chip in
  • k and k1 = rows 1-6 of the zeros board (k for Player2 and k1 for Player1)
  • j and j1 = columns 1-4 of the zeros board for each player
  • l and l1 = start at 0, step by 1, end at 3 in the for loop
  • m and m1 = columns 1-7 of the zeros board (m for Player2 and m1 for Player1)
  • n and n1 = rows 1-4 of the zeros board for each player
  • b and b1 = start at 0, step by 1, end at 3 in the for loop
  • u and u1 = rows 1-4 of the zeros board (u for Player2 and u1 for Player1)
  • o and o1 = columns 4-6 of the zeros board for each player
  • g and g1 =start at 0, step by1, end at 3 in the for loop
  • t and t1 = columns 1-7 of the zeros board (t for Player2 and t1 for Player1)
  • c and c1 = rows 4-6 of the zeros board for each player
  • q and q1 = start at 0, step by 1, end at 3 in the for loop

A List of Every Command Used:

  • load(‘Connect.mat’) : load the Connect 4 data provided on Carmen
  • imshow([Board{1,:}:Board{2,:};…Board{6,:}]) : show the blank Connect 4 board
  • fprintf(‘\nText goes here’) : used to print instructions, welcome statement, and any other text.
  • input(‘Question/Command for the user to answer here’) : used to ask the user which player is starting and for the coordinate of their move
  • while loop : counts down how many turns there are left after every move, continues until the game is either won by a player or there are no more turns
  • if/else statement : if the player is even (player 2) then they will enter the coordinates of their turn, else the player is odd (player 1) and they will enter the coordinates of their turn
  • Board{I,J} or Board{x,y} : inputs the players’ move coordinates into the Connect 4 board.
  • Player2(positionx,positiony) or Player1(positionx,positiony)=1 : assigns the value 1 to the player’s turn in their zeros board
  • For loops : To check if a player has won, two for loops are nested into one big for loop that sums the player’s zero board by row, column, and diagonally
  • If/else statement outside the while loop : if the sum of either player’s zeros board is 4, the player has won and the statement is printed to the screen.