I. Mastermind

The primary components needed for Mastermind are a loop to execute ten times, a randomized code, and logic to check guesses to the randomized code. Secondary components included in the program are a graphical display and input checking. The graphical display was provided. The input checking checks for repeated numbers in a single guess and for invalid characters. The loop is done using a for loop which executes ten times and contains almost all of the code. The randomized code is done using randperm() which makes a random number of integers depending on arguments that do not repeat. The logic to check the code works by running through every single element of the guess and comparing them to every single element of the actual code, and adds to a variable to handle white pegs for that. Later on in the program, the check is performed again, but this time it checks all values that have the same index in both vectors (it compares guess(1) with code(1) then guess(2) with code(2) etc.) and adds the number of matches to a vector for black pegs then subtracts that same number from the variable that handles white pegs, as that variable also included the count of black pegs.


VARIABLES

a, k, n, q: all used as indices for loops

black: the number of black pegs (or the number of correct colors in the correct place)

Blue, Red, Green, Yellow, Orange, Turquoise, Pink, BlackPeg, WhitePeg: used by graphical representation to be colors on the board

Board: used by graphical representation as the board itself that displays

code: represents the randomly generated code that the user is trying to guess

codeEval: copy of code used for checking the guess against for number of white pegs

given: string that represents the user’s input for a guess

guess: vector that represents the user’s entire guess for a turn

guessEval: similar to codeEval and compared against it

invalid: starts as 0 but turns to 1 if an invalid input is detected

losing: starts as 1 but turns to 0 if an invalid input is detected or the game is won

white: represents number or white and black pegs, and is later reduced to the number of white pegs


PROVIDED GAME COMMANDS

imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:};Board{7,:};Board{8,:};Board{9,:};Board{10,:}]) Shows the board

Blue, Red, Green, Yellow, Orange, Turquoise, Pink, BlackPeg, WhitePeg: represent each possible color for a peg

Ossman, K. and Bucks, G. , “MATLAB Courseware: Game Projects” , MathWorks,
https://www.mathworks.com/academia/highschool/courseware
/games/?s_tid=srchtitle