Printing what was right on a guess

This commit is contained in:
Matúš Púll 2024-11-02 17:13:32 +01:00
parent b41dfcb303
commit 3e5bdb52e0

View file

@ -49,3 +49,34 @@ string format_guess(vector<int> guess) {
r += "\n"; r += "\n";
return r; 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;
}