Mastermind Help. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Mastermind Help.

AphilliosAphillios Posts: 27Member
So I'm making a version of Mastermind, and I'm having problem with the mechanics. I've got it to find out the correct ones easily enough, I'm just having problems with the right but in wrong place blocks.

And duplicate entries are also kicking my ass >.<

[code]
// This method must return the response comparing the user guess with secret code
// The output may be "BBWW" or "WW" or simply "" (if all colors are wrong)
public String getResponse(String s)
{
String response = "";
boolean correct = false;
boolean first = false;
boolean guess = false;

for(int i = 0; i < secret.length(); i++)
{

if (s.charAt(i) == secret.charAt(i))
{
response += "B";
correct = true;
s.replace(s.charAt(i), 'O');
}
if (correct == false)
{
for (int j = 0; j < secret.length(); j++)
{

// if (secret.charAt(i) == secret.charAt(j) && correct == true)
// guess = true;

if (secret.charAt(i) == s.charAt(j) && guess == false)
{
response += "W";
guess = true;

}


}
}
}

return response;
}

[/code]

Any help would be appreciated.
Sign In or Register to comment.