Exemplo n.º 1
0
void GuessResponse::setCorrectNumber(const Code &secret, const Code &guess)
{
	// iterate through each, marking when a code place is accounted for
	for (int i = 0; i < secret.GetLength(); i++)
	{
		if (secret.GetValue(i) == guess.GetValue(i))
		{
			_numberCorrect++;
			guessCodeMemberAccountedFor[i] = true;
			secretCodeMemberAccountedFor[i] = true;
		}
	}
}
Exemplo n.º 2
0
void GuessResponse::setMisplacedNumber(const Code &secret, const Code &guess)
{
	bool exitNest = false;
	// iterate through each, noting and marking when a code place is accounted for
	for (int i = 0; i < guess.GetLength(); i++)
	{
		exitNest = false;
		if (guessCodeMemberAccountedFor[i]) continue;

		for (int j = 0; j < secret.GetLength(); j++)
		{
			if (exitNest || secretCodeMemberAccountedFor[j]) continue;

			else if (guess.GetValue(i) == secret.GetValue(j))
			{
				_numberMisplaced++;
				guessCodeMemberAccountedFor[i] = true;
				secretCodeMemberAccountedFor[j] = true;
				exitNest = true;
			}
		}
	}
}