Responses should be enums

This commit is contained in:
Matúš Púll 2024-12-04 12:16:40 +01:00
parent 5b908ef7dd
commit 48042b7d15
4 changed files with 14 additions and 7 deletions

View file

@ -9,9 +9,9 @@ using std::to_string;
#define UNDERLINE "\033[0;0;4m"
string format_response(vector<int> response) {
return YELLOW + to_string(response[0]) + BACK + " / " +
GREEN + to_string(response[1]) + BACK + "\n";
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 = "";

View file

@ -8,16 +8,22 @@ using std::string;
using std::cout;
using std::cin;
// Generic type
struct Response {
int somewhere, correct;
Response() {}
Response(int _s, int _c) : somewhere(_s), correct(_c) {}
};
// Game generating
string get_input(string arg, vector<string> args, string prompt_text, string default_arg);
vector<int> generate(int N, int M);
// Formatting
string format_response(vector<int> response);
string format_response(Response response);
string format_guess(vector<int> guess);
string format_guess_history(vector<int> sequence, vector<int> guess);
string format_lost_sequence(vector<int> sequence);
// Validating
vector<int> validate(vector<int> sequence, vector<int> guess);
Response validate(vector<int> sequence, vector<int> guess);

View file

@ -54,7 +54,8 @@ int main(int argc, char* argv[]) {
// Guessing
vector<vector<int>> history = {};
for(int guesses = 0; guesses < 10; guesses++) {
vector<int> guess(N), response;
vector<int> guess(N);
Response response;
// Bot playin
if(player == BOT) {

View file

@ -1,7 +1,7 @@
#include "global.hpp"
vector<int> validate(vector<int> sequence, vector<int> guess) {
Response validate(vector<int> sequence, vector<int> guess) {
int N = sequence.size();
// Return values