Pseudocode
Clear the stored variables
Clear the command window
load Mastermind
display the blank board
establish which numbers correspond to which colors and that colors will not be repeated
NumberToColor = {Red, Green, Blue, Yellow, Purple, Pink, Orange, Turquoise};
Establish random code
Establish default state as losing
for k = [1:10]
start with no black pegs
start with no white pegs
start with no guess
for n = [1:4]
ask guess for a position n
pick up input as guess
set up vector to convert number of guess to color
make the board correct with the guess
end
for n = [1:4]
for q = [1:4]
if q ~= n
if guess(q) == guess(n)
if the input has repeated colors or invalid entries this stops the game
end
end
end
end
if the input is invalid
say the input is invalid
use a boolean to cancel the losing condition
end the program
end
create a copy of the code to manipulate
a = 1;
while a <= 4
q = 1;
while q <=length of the copy of the code
if the indices are not the same
if the guess at a given point is equal to the code at a different given point
add a white peg
remove the value from the copy of the code
reset index q
reset index a
else
increment q
end
else
increment q
end
end
increment a
end
for n = [1:4]
if the guess at appoint is equal to the code at the same point
add a black peg
end
end
for every black peg
put the black peg on the board
end
for every white peg
put the white peg on the baord
end
show the board
if there are four black pegs
print You won!
use a Boolean to show the winning condition has been met
break
end
end
if a winning condition has not been met
print Better luck next time!
end
Flowchart