Basic Layout and implementations of Mastermind Helper Methods
This commit is contained in:
parent
709475cfc3
commit
b555d3d5c8
@ -5,10 +5,12 @@
|
|||||||
#include "Aufg2/GuestList.h"
|
#include "Aufg2/GuestList.h"
|
||||||
#include "Aufg3/Phonebook.h"
|
#include "Aufg3/Phonebook.h"
|
||||||
#include "Aufg4/CrimeStats.h"
|
#include "Aufg4/CrimeStats.h"
|
||||||
|
#include "Aufg5/Mastermind.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Aufg1Main();
|
// Aufg1Main();
|
||||||
// Aufg2Main();
|
// Aufg2Main();
|
||||||
// Aufg3Main();
|
// Aufg3Main();
|
||||||
Aufg4Main();
|
// Aufg4Main();
|
||||||
|
Aufg5Main();
|
||||||
}
|
}
|
56
Aufg5/Mastermind.cpp
Normal file
56
Aufg5/Mastermind.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
//
|
||||||
|
// Created by DH10MBO on 13.11.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Mastermind.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Aufg5Main() {
|
||||||
|
// generateSecretCode(1,1);
|
||||||
|
|
||||||
|
std::vector<std::string> SecretCode = generateSecretCode(4, 4);
|
||||||
|
|
||||||
|
printAllStringsInVector(SecretCode);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
22
Aufg5/Mastermind.h
Normal file
22
Aufg5/Mastermind.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// Created by DH10MBO on 13.11.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MASTERMIND_H
|
||||||
|
#define MASTERMIND_H
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
void Aufg5Main();
|
||||||
|
|
||||||
|
std::vector<std::string> generateSecretCode(int size, int optionsPerDigit);
|
||||||
|
|
||||||
|
std::vector<std::string> getCodeGuessFromConsole();
|
||||||
|
|
||||||
|
std::vector<std::string> convertStringToGuess(std::string &guessAsString);
|
||||||
|
|
||||||
|
int countMatches(std::vector<std::string> &v1, std::vector<std::string> &v2);
|
||||||
|
|
||||||
|
int countPefectMatches(std::vector<std::string> &v1, std::vector<std::string> &v2);
|
||||||
|
|
||||||
|
#endif //MASTERMIND_H
|
Loading…
Reference in New Issue
Block a user