S3_Cpp/Aufg5/Mastermind.cpp
2024-11-13 21:11:45 +01:00

75 lines
1.5 KiB
C++

//
// Created by DH10MBO on 13.11.2024.
//
#include "Mastermind.h"
#include <iostream>
#include <ostream>
#include <random>
#include "../Aufg4/CrimeStats.h"
int getRandomNumberInRange(int min, int max) {
static std::mt19937 generator(static_cast<unsigned int>(time(nullptr)));
std::uniform_int_distribution<int> distribution(min, max);
int randomNumber = distribution(generator);
return randomNumber;
}
void printAllStringsInVector(std::vector<std::string> &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<std::string> generateSecretCode(int digits, int optionsPerDigit) {
std::vector<std::string> 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<std::string> getCodeGuessFromConsole() {
std::cout << "Have a Guess! :" << std::endl;
std::string input;
std::cin >> input;
std::vector<std::string> guess;
split(input, ' ', guess);
return guess;
}
void Aufg5Main() {
// generateSecretCode(1,1);
std::vector<std::string> SecretCode = generateSecretCode(4, 4);
printAllStringsInVector(SecretCode);
std::vector<std::string> guess = getCodeGuessFromConsole();
printAllStringsInVector(guess);
}