C. Program Description for Developers

Blackjack

This form of Blackjack is slightly modified from the original version. In this version, there is no set pot that gradually decreases as the player plays multiple rounds. Instead, to make the game more appealing to all ages, the bet is reset each time the player plays the game, and the player can choose any amount between $5 and $100. To begin the game, the player input their bet. Next, the cards are shuffled so that they can be “dealt” to both the player and the dealer. This is accomplished by setting 4 vectors (representing the 4 suits) of 13 cards each. This is represented by variables D1-4. Each row is shuffled by using the randperm function for each vector and naming these shuffled decks ShuffledRow1-4. These rows are put into a vector named ShuffledDeck. the first card of each ShuffledRow makes up the cards in the player’s hand. These cards are represented by Card1-4. The first 2 cards of the player’s hand are displayed and so is the sum of these cards, which is represented with Sum_of_Cards. The dealer’s deck is created in the same way, but the rows of cards are represented by D1b-4b, and ShuffledRow1b-4b. The Dealer_Hand contains Dealer_Card1-4, and the dealer’s first card is displayed as Dealer_Sum_of_Cards.

Now that the deck is shuffled, it is time for the player to go through their round. An if-else loop is used to determine the different outcomes and potential sums of the player’s cards as related to 21. These outcomes set the variable W to a number that will be referenced in the results loop. They also set A equal to a number that determines whether or not the other loops will run. The next loops either happen or don’t depending on the outcomes from the previous loops and their A values. The dealer then runs through their turn in a similar fashion as the player, using the A values from the dealer’s rounds to determine whether or not the if-else loops are used.

Finally, the results list is run. This if-else loop uses the W variable from the rest of the code to display the results for the winner of the game and the money earned or lost by the player. The variable Final_Money_Value is how much the player makes or loses, and it manipulates the variable Bet from the beginning of the code with the sum function. Final results are displayed with fprintf statements.

Connect Four

Not all variables in the final code are used in the final game, but can still be seen in the code. This description only includes the active variables and functions.

The starting welcome display is used with the fprintf function, which displays whatever is in the following parenthesis. Next is the input function, which has a different result depending on what the user inputs. This case is asking if both players know how to play, then the user either types 1 for yes or 2 for no. This is set to variable “x”. An if loop is then used so if the user inputs “1”, the game starts, if the user inputs “2”, the written instructions are displayed. Creating the Connect Four grid and playing pieces were done using linspace, cos, and sin functions. These made specific dimensions of the grid and pieces and were set to variables “circle”, “circle1”, and “circle2”. After that, variables RW and ClM were set to 6 and 7 to make the 6×7 grid with the zeros function making every part of the grid have a value of 0. This creates the grid of empty spots at the start of a game and the abs function is used to make every input a positive integer. The patch function plots regions of the x and y elements with x being “circle1” and y being “circle2”. To further make the grid resemble a real Connect Four game, the title was added using the title function, and set(gca,’YTick’,[]) and set(gca,’XTick’,[]) changes the objects graphics, sets the current axes, and removes the x and y axis borders. Then, the grid on function turns the grid on to display. To make the game continue to run off of Player 1 and 2 alternating turns, a for loop was used and set to variable “z”. To tell which Players turn it is at the time, the disp function was added, and is functionally the same as the fprintf function used previously. The players are able to add their pieces to the grid with the ginput function. This loop also contains the round function set to variables “a” and “b” which makes values whole numbers, and the entire graph is set to 1. Set(grid(a,b),’FaceColor’,[customColor]) allows the user to choose from a range of custom colors at the start of each turn. To finish, an if loop was added to ensure the game runs as intended. It will loop if abs(a,b) is greater than -1000, and since abs(a,b) is a positive integer, this statement is true and the if loop will run as intended.