When creating these games, we created and utilized different functions outlined in the lists below. For Connect 4, we utilized different levels of an AI. Apart from the CPU function which is designed to tell the computer to play aggressively, instead of playing the game defensively, we also created a Score function which calculated a “score” based on the same colored chips surrounding a specific chip. The first level is a random generator for the computer to determine where to place its chip. Level 2 utilizes the score system and a random number, so that the computer makes a few mistakes. Level 3 uses the score system solely. Level 4 the score system is fine tuned to be more precise by getting rid of meaningless points.
Hangman:
Game Commands:
displayWord– tells the computer what to display (blank wise)
Variable :
m– a temporary variable that you replace the letter you haven’t guessed with a blank
output– you add spaces between the blanks, to display the word better
game– if the game is running
Images – Imported from the Hangman.mat file, contains the the images that create the hangman, a total of 6 different images that make up the guy getting hung
p– a temporary variable that means the players input
gamestatus– if you win or lose
index– temporary to chose a word from the word list
word– the word is the randomly selected word for one of the word lists
Movies– Word lists imported from the Hangman.mat file
States – word lists imported from the Hangman.m file
Songs– word lists imported from the Hangman.m file
toGuess– A vector that stores ones and zeros, 1 means the corresponding letter is not guessed and a zero means guessed and filled.
tries– how many wrong guesses you have tried
charGuessed– The letter you have already guessed
inputchar- the variable stores the user’s input (letter)
Connect Four:
Command:
Win– function that tells you if there is a winner, who the winner is, or a tie from the existing board
score– helps determine where the AI will place, a high score means valuable move
graphBoard– the function that graphs the animation of dropping the chip onto the board
CPU– the determines the computers choice based on difficulty, score reading and the board
chip– the function that tells you which row the chip will stop when you place it in a column
Variables:
winner– what player wins, -1 means it is a draw, 0 means no one wins, 1 means player wins, 2 means AI wins
m– the board, 6 by 7 matrix to tell which space is empty, and which chips are in the spaces, 0 means empty, 1 means players chip, 2 means computers chip
s– output of the score
c– going to calculate the score for either player or computer
diff– the difficulty
h, v, d1,d2 – horizontal, vertical, diagonal left-right, diagonal right-left, number of chips in that direction
hs, vs, d1s, d2s– horizontal, vertical, diagonal left-right, diagonal right-left, empty spaces in that direction
hf, vf, d1f, d2f– horizontal, vertical, diagonal left-right, diagonal right-left, when checking that direction and encounters an empty spot and sets to be false to stop counting the number of connected chips
x1, y1– the position that the function is checking to count the chips to calculate the score
Blank– image of a blank spot on the board
Board– current images of the board
Chip– image you are dropping
i– index for forloop
choice– which row it is going to drop
choices– the score of all the choices from 1-7
s1– offensive score
s2– defensive score
choices(i)– the score for the column i
m1,m2– temporary board if you put a chip at someplace used to determine if that move will create a winner
maxscore– the highest score from all 7 choices
finalchoices– the choice that has the same score as the max score
game– tells whether the game is running
winner– who wins
p– players input for the chip 1-7, the column number, for the column you are drooping the chip
l– row of the chip will stop after placing it in a column
redchip– the image of the red chip for the player
blackchip- the image of the black chip for the computer
output- the resulting row if you put a chip in a certain column