From 48042b7d1526a0681335812cd87a34063e0741ac Mon Sep 17 00:00:00 2001 From: Matuush Date: Wed, 4 Dec 2024 12:16:40 +0100 Subject: [PATCH] Responses should be enums --- format.cpp | 6 +++--- global.hpp | 10 ++++++++-- main.cpp | 3 ++- validate.cpp | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/format.cpp b/format.cpp index 7e5b255..06187f2 100644 --- a/format.cpp +++ b/format.cpp @@ -9,9 +9,9 @@ using std::to_string; #define UNDERLINE "\033[0;0;4m" -string format_response(vector 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 guess) { string r = ""; diff --git a/global.hpp b/global.hpp index 456923d..1ba974a 100644 --- a/global.hpp +++ b/global.hpp @@ -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 args, string prompt_text, string default_arg); vector generate(int N, int M); // Formatting -string format_response(vector response); +string format_response(Response response); string format_guess(vector guess); string format_guess_history(vector sequence, vector guess); string format_lost_sequence(vector sequence); // Validating -vector validate(vector sequence, vector guess); +Response validate(vector sequence, vector guess); diff --git a/main.cpp b/main.cpp index 9c9c2f8..d562a60 100644 --- a/main.cpp +++ b/main.cpp @@ -54,7 +54,8 @@ int main(int argc, char* argv[]) { // Guessing vector> history = {}; for(int guesses = 0; guesses < 10; guesses++) { - vector guess(N), response; + vector guess(N); + Response response; // Bot playin if(player == BOT) { diff --git a/validate.cpp b/validate.cpp index 47952a5..11a78c1 100644 --- a/validate.cpp +++ b/validate.cpp @@ -1,7 +1,7 @@ #include "global.hpp" -vector validate(vector sequence, vector guess) { +Response validate(vector sequence, vector guess) { int N = sequence.size(); // Return values