66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
#include "global.hpp"
|
|
|
|
using std::to_string;
|
|
|
|
#define YELLOW "\033[33m"
|
|
#define GREEN "\033[32m"
|
|
#define RED "\033[31m"
|
|
#define BACK "\033[0;0;0m"
|
|
#define UNDERLINE "\033[0;0;4m"
|
|
|
|
|
|
string format_response(Response response) {
|
|
return YELLOW + to_string(response.somewhere) + BACK + " / " +
|
|
GREEN + to_string(response.correct) + BACK + "\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] = GREEN + to_string(guess[i]) + BACK;
|
|
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] = YELLOW + to_string(guess[i]) + BACK;
|
|
guess[i] = -1;
|
|
sequence[j] = -1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Remaining values
|
|
for(int i = 0; i < N; i++) {
|
|
if(guess[i] != -1)
|
|
r[i] = to_string(guess[i]);
|
|
}
|
|
|
|
string r_string = "";
|
|
for(string s : r)
|
|
r_string += s + " ";
|
|
return r_string;
|
|
}
|
|
|
|
string format_lost_sequence(vector<int> sequence) {
|
|
string r = "";
|
|
for(int col : sequence)
|
|
r += RED + to_string(col) + BACK + " ";
|
|
return r;
|
|
}
|