本文整理汇总了C++中code::getGuess方法的典型用法代码示例。如果您正苦于以下问题:C++ code::getGuess方法的具体用法?C++ code::getGuess怎么用?C++ code::getGuess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code
的用法示例。
在下文中一共展示了code::getGuess方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkCorrect
// input:
// code guess - a code object containing the user's guess
// output:
// int correct - the number of digits in the guess that are correctly placed to the secret
//
// Check how many digits of a guess are correctly placed compared to the secret code. When a correct digit is found
// the corresponding digit in the USER'S GUESS is set to 6 since 6 is above the possible range. This indicates that
// the index has been covered. The secretDigit value at the same index is also set to 6 since secretDigit represents the
// remaining part of the secret to be guessed.
// ASSUMPTION: This is called BEFORE checkIncorrect so that it may update the guess with correctly guessed digits
int code::checkCorrect(code guess) {
vector<int> userGuess = guess.getGuess();
vector<int> secretCode = getSecret();
vector<int> secretDigits = getDigits();
int correct = 0;
for (int i=0; i < userGuess.size(); i++) {
//Correct digit placement found
if (userGuess[i] == secretDigits[i] && secretDigits[i] != 6) {
userGuess[i] = 6;
secretDigits[i] = 6;
correct += 1;
}
}
setGuess(userGuess);
setDigits(secretDigits);
return correct;
}
示例2: checkIncorrect
// input:
// code guess - a code object containing the user's guess
// output:
// int incorrect - the number of digits in the guess that exist in the secret, but are not correctly placed
//
// Check how many digits are part of the secret code, but were guessed at wrong positions. If an index is set to 6
// we know that the index has been covered and will skip it. If an element in the same spot in secretDigits is set to 6,
// this also means that the value has been covered.
// ASSUMPTION: This is called AFTER checkIncorrect so that it will only check indices that haven't been confirmed
int code::checkIncorrect(code guess) {
vector<int> userGuess = guess.getGuess();
vector<int> secretCode = guess.getSecret();
vector<int> secretDigits = getDigits();
int incorrect = 0;
for (int i=0; i < userGuess.size(); i++) {
//Index has already been confirmed, move on
if (userGuess[i] == 6) {
continue;
}
//Digit IS part of solution, HAS NOT been verified by checkCorrect, but in wrong place
if (find(secretDigits.begin(), secretDigits.end(), userGuess[i]) != secretDigits.end() && userGuess[i] != secretDigits[i] && secretDigits[i] != 6) {
incorrect += 1;
userGuess[i] = 6;
secretDigits[distance( secretDigits.begin(), find(secretDigits.begin(), secretDigits.end(), userGuess[i]))] = 6;
}
}
setDigits(secretDigits);
return incorrect;
}