diff --git a/ActualMain.cpp b/ActualMain.cpp index 0a8ab50..ac4a4f0 100644 --- a/ActualMain.cpp +++ b/ActualMain.cpp @@ -5,10 +5,12 @@ #include "Aufg2/GuestList.h" #include "Aufg3/Phonebook.h" #include "Aufg4/CrimeStats.h" +#include "Aufg5/Mastermind.h" int main() { // Aufg1Main(); // Aufg2Main(); // Aufg3Main(); - Aufg4Main(); -} \ No newline at end of file + // Aufg4Main(); + Aufg5Main(); +} diff --git a/Aufg5/Mastermind.cpp b/Aufg5/Mastermind.cpp new file mode 100644 index 0000000..0cdfa41 --- /dev/null +++ b/Aufg5/Mastermind.cpp @@ -0,0 +1,56 @@ +// +// Created by DH10MBO on 13.11.2024. +// + +#include "Mastermind.h" + +#include +#include +#include + +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; +} + + + + + + + + +void Aufg5Main() { + // generateSecretCode(1,1); + + std::vector SecretCode = generateSecretCode(4, 4); + + printAllStringsInVector(SecretCode); + + +} diff --git a/Aufg5/Mastermind.h b/Aufg5/Mastermind.h new file mode 100644 index 0000000..4f076c2 --- /dev/null +++ b/Aufg5/Mastermind.h @@ -0,0 +1,22 @@ +// +// Created by DH10MBO on 13.11.2024. +// + +#ifndef MASTERMIND_H +#define MASTERMIND_H +#include +#include + +void Aufg5Main(); + +std::vector generateSecretCode(int size, int optionsPerDigit); + +std::vector getCodeGuessFromConsole(); + +std::vector convertStringToGuess(std::string &guessAsString); + +int countMatches(std::vector &v1, std::vector &v2); + +int countPefectMatches(std::vector &v1, std::vector &v2); + +#endif //MASTERMIND_H