82 lines
1.7 KiB
C++
82 lines
1.7 KiB
C++
#pragma once
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
using std::vector;
|
|
using std::string;
|
|
using std::to_string;
|
|
|
|
vector<int> validate(vector<int> sequence, vector<int> guess) {
|
|
int S = sequence.size();
|
|
|
|
// Return values
|
|
int r_correct = 0;
|
|
int r_somewhere = 0;
|
|
|
|
// Find and remove correct values
|
|
for(int i = 0; i < S; i++) {
|
|
if(sequence[i] == guess[i]) {
|
|
r_correct++;
|
|
sequence.erase(sequence.begin()+i);
|
|
guess.erase(guess.begin()+i);
|
|
i--;
|
|
S--;
|
|
}
|
|
}
|
|
|
|
// Find values that are there somewhere
|
|
for(int col : guess) {
|
|
for(int i = 0; i < S; i++) {
|
|
if(sequence[i] == col) {
|
|
r_somewhere++;
|
|
sequence.erase(sequence.begin()+i);
|
|
S--;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return {r_somewhere, r_correct};
|
|
}
|
|
|
|
string format_response(vector<int> response) {
|
|
return to_string(response[0]) + " somewhere / " + to_string(response[1]) + "on the right spot\n";
|
|
}
|
|
string format_guess(vector<int> guess) {
|
|
string r = "";
|
|
for(int col : guess)
|
|
r += to_string(col) + " ";
|
|
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;
|
|
}
|