Connect Four was created using a series of loops to check the position of player one and player two’s chips on the game board (in the matrix) at all times. The loops begin checking the chip positioning once four chips have been entered into the matrix (the game board). It then checks a single direction until the same color chip isn’t next to it and moves on to another direction. Overall it checks up, down, and all four diagonals of both chips, outputting that someone has won if it recognizes four same colored chips in the game board in a single direction. The game code was formatted to allow two users to input column numbers to place a connect four chip in one of the seven columns. Entering a one places a chip in the leftmost column, and seven places a chip in the rightmost column. The players move was then displayed on a figure that is constantly displayed each new move in alternating red and black chips. Initial testing failed in the code creation as the checks for up, down, and the diagonals were constantly outputting error messages, so refinements had to be made to the code. The code was fixed as we realized it was checking the incorrect columns which was discovered through drawing out the matrix by hand. The game is played until someone wins by connecting four same colored chips in a row horizontally, vertically, or diagonally, or until the game board (matrix) becomes completely filled up.
Rock Paper Scissors was created using a set of if-else statements to check the entered move of the user against the computers move. The user is first prompted to enter a certain value for rock, paper, or scissors. A while loop then begins which loops until the user decides to quit. The rules for this game are the same as regular rock paper scissors. Rock beats scissors, scissors beats paper, and paper beats rock. If the computer wins, a point is added to the computer’s score. If the user wins, a point is added to the user’s score. If it is a tie, neither the computer nor the user get a point. When the user enters the value to quit, the scores of both the computer and the user are displayed.
Over Under was created using a set of if-else statements to check if the user’s guess was correct. The user is first prompted to enter a bet value that is between 0 and the amount in the pool (which begins at 100). If the user enters 0, the game is quit. When the user enters a value, a while loop begins which can be quit when the user enters 0. The user is then prompted to enter if they think the rolls will be higher, lower, or equal to seven. The dice are then “rolled” using a random number between 1 and 6. The rolls are added up. The two rolls are also displayed in the dice graphics. If the user correctly guessed that the roll would be higher or lower than seven, the amount they bet is added into their pool. If they correctly guessed that the roll would be exactly seven, four times the amount they bet is added into their pool. If they incorrectly guessed, then the amount they guessed is subtracted from their pool. The user is again prompted to bet or quit.
The What are the Odds game was made using a series of several if and elseif statements to compare user inputs and randomly generated values to determine whether or not the user must do the given dare. After a a value is randomly generated to determine the bet that the will have to perform, the user is prompted to input odds that they will do that bet. Then a user input number and computer generated value between the bounds of 1 and the odds are compared. If the values are equal, then the user must perform the bet, and if the values are not equal, then the user is not required to perform the bet. At first, the bets were written in a text file, and the program would load the text file into the program to make the code more concise. However, there was an issue loading entire sentence strings into a vector, as the spaces caused inconsistent amounts of columns in the text file leading to an issue in loading the data into the program. Then the sentence strings were assigned to variables, and the variables inserted into a vector. However, this also returned errors from MATLAB. To solve these errors, a long series of if statements were made depending on a number generated between 1 and the number of dares that the group came up with. Though the code may not be the most efficient, it allowed the game to successfully work.