diff --git a/Aufg5/Mastermind.cpp b/Aufg5/Mastermind.cpp index efb2151..2f4ec96 100644 --- a/Aufg5/Mastermind.cpp +++ b/Aufg5/Mastermind.cpp @@ -32,21 +32,21 @@ std::vector generateSecretCode(int digits, int optionsPerDigit) { std::vector secretCode; for (int i = 0; i < digits; i++) { - int digit = getRandomNumberInRange(0, optionsPerDigit); + int digit = getRandomNumberInRange(1, optionsPerDigit); secretCode.push_back(std::to_string(digit)); - std::cout << "Secret Code was set as " << digit << std::endl; + // std::cout << "Secret Code was set as " << digit << std::endl; } return secretCode; } -std::vector getCodeGuessFromConsole() { +std::vector getCodeGuessFromConsole(int codeLength) { std::cout << "Have a Guess!" << std::endl; std::vector guess; // TODO Make limit dynamic - for (int i = 1; i < 5; ++i) { + for (int i = 1; i <= codeLength; ++i) { // std::cout << "Enter Digit " << i << " : " << std::endl; std::string input; std::cin >> input; @@ -103,21 +103,37 @@ int countMatches(std::vector &v1, std::vector &v2) { return count; } - - - - - - void Aufg5Main() { - // generateSecretCode(1,1); + int optionsPerDigit = 4; + int codeLength = 4; + int livesRemaining = 5; + std::cout << optionsPerDigit << " options per Digit" << std::endl; + std::cout << codeLength << " Code Length" << std::endl; + std::cout << livesRemaining << " Lives Remaining" << std::endl; + std::vector SecretCode = generateSecretCode(codeLength, optionsPerDigit); - std::vector SecretCode = generateSecretCode(4, 4); + std::cout << "I have locked the door with a secret Code, you will never be able to figure it out!!" << std::endl; + // printAllStringsInVector(SecretCode); + int perfectCounter = 1; + while (perfectCounter && livesRemaining) { + std::vector guess = getCodeGuessFromConsole(codeLength); + + perfectCounter = countPefectMatches(guess, SecretCode); + + std::cout << "correct were: " << countMatches(guess, SecretCode) << std::endl; + std::cout << "perfect were: " << perfectCounter << std::endl; + + livesRemaining--; + + if (perfectCounter == codeLength) { + std::cout << "No! This cant be!" << std::endl << "How did you know???" << std::endl << "What kind of Computer Nerd are you?!?"; + return; + } + } + + std::cout << "You Lost!" << std::endl << "My Secret Code stays a Mystery!!!" << std::endl << std::endl << "Fine, I will tell you" << std::endl; printAllStringsInVector(SecretCode); - - std::vector guess = getCodeGuessFromConsole(); - std::cout << "correct were: " << countMatches(guess, SecretCode) << std::endl; - std::cout << "perfect were: " << countPefectMatches(guess, SecretCode) << std::endl; + std::cout << "NERD ㄟ(≧◇≦)ㄏ"; }