// // Created by DH10MBO on 13.11.2024. // #include "Mastermind.h" #include #include #include #include "../Aufg4/CrimeStats.h" int getRandomNumberInRange(int min, int max) { static std::mt19937 generator(static_cast(time(nullptr))); std::uniform_int_distribution distribution(min, max); int randomNumber = distribution(generator); return randomNumber; } void printAllStringsInVector(std::vector &strings) { std::cout << "["; int i; for (i = 0; i < strings.size() - 1; i++) { std::cout << strings[i] << ", "; } std::cout << strings[i] << "]" << std::endl; } std::vector generateSecretCode(int digits, int optionsPerDigit) { std::vector secretCode; for (int i = 0; i < digits; i++) { int digit = getRandomNumberInRange(0, optionsPerDigit); secretCode.push_back(std::to_string(digit)); std::cout << "Secret Code was set as " << digit << std::endl; } return secretCode; } std::vector getCodeGuessFromConsole() { std::cout << "Have a Guess!" << std::endl; std::vector guess; // TODO Make limit dynamic for (int i = 1; i < 5; ++i) { std::cout << "Enter Digit " << i << " : " << std::endl; std::string input; std::cin >> input; guess.push_back(input); } std::cout << "You entered: " << std::endl; printAllStringsInVector(guess); return guess; } int countPefectMatches(std::vector &v1, std::vector &v2) { int shorterSize; if (v1.size() < v2.size()) { shorterSize = v1.size(); } else { shorterSize = v2.size(); } int count = 0; for (int i = 0; i < shorterSize; i++) { if (v1[i] == v2[i]) { count++; } } return count; } void Aufg5Main() { // generateSecretCode(1,1); std::vector SecretCode = generateSecretCode(4, 4); printAllStringsInVector(SecretCode); std::vector guess = getCodeGuessFromConsole(); std::cout << "correct were: " << countPefectMatches(guess, SecretCode) << std::endl; }