hi, im new here and looking for some help with a mastermind game i have to program for school. this is the first thing i have programmed and so plz keep the solutions simple.
if anyone knows how to play mastermind, they will know that there is a correct colour wrong location pin (the white one) i need to write some code which will scan through my array of colours and tell me how many near matches i have, the problem is i cannot get it to work. logically it is correct and works when desk checked, but for some reason i do not get the correct answer.
plz help
thanks
mitch
my code (this is just the procedure which does not work, it is not the whole game)
if anyone knows how to play mastermind, they will know that there is a correct colour wrong location pin (the white one) i need to write some code which will scan through my array of colours and tell me how many near matches i have, the problem is i cannot get it to work. logically it is correct and works when desk checked, but for some reason i do not get the correct answer.
plz help
thanks
mitch
my code (this is just the procedure which does not work, it is not the whole game)
Code:
function countNearMatches: integer;
var
i, j : integer;
solutionCopy : ColourArray;
guessCopy : ColourArray;
begin
countNearMatches := 0;
guessCopy := guess;
solutionCopy := solution;
for i := 0 to CODELENGTH-1 do
begin
for j := 0 to CODELENGTH-1 do
begin
if (guessCopy [i] = solutionCopy [j])
and (i <> j)
and (guessCopy[i] <> NULL)
and (solutionCopy[j] <> NULL) then
begin
countNearMatches := countNearMatches + 1;
guessCopy[i] := NULL;
SolutionCopy[j] := NULL;
end;
end;
end;
end;