Printing what was right on a guess
This commit is contained in:
parent
b41dfcb303
commit
3e5bdb52e0
1 changed files with 31 additions and 0 deletions
31
validate.hpp
31
validate.hpp
|
@ -49,3 +49,34 @@ string format_guess(vector<int> guess) {
|
|||
r += "\n";
|
||||
return r;
|
||||
}
|
||||
|
||||
string format_guess_history(vector<int> sequence, vector<int> guess) {
|
||||
vector<string> r(sequence.size());
|
||||
int N = sequence.size()
|
||||
// Find correct values
|
||||
for(int i = 0; i < N; i++) {
|
||||
if(sequence[i] == guess[i]) {
|
||||
r[i] = "\033[32m" + to_string(guess[i]) + "\033[0m";
|
||||
guess[i] = -1;
|
||||
sequence[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Find values that are there somewhere
|
||||
for(int i = 0; i < N; i++) {
|
||||
if(guess[i] == -1) continue;
|
||||
for(int j = 0; j < N; j++) {
|
||||
if(sequence[j] == guess[i]) {
|
||||
r[i] = "\033[32m" + to_string(guess[i]) + "\033[0m";
|
||||
guess[i] = -1;
|
||||
sequence[i] = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string r_string = "";
|
||||
for(string s : r)
|
||||
r_string += s;
|
||||
return r_string;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue