diff --git a/ActualMain.cpp b/ActualMain.cpp index ac4a4f0..870f58f 100644 --- a/ActualMain.cpp +++ b/ActualMain.cpp @@ -6,11 +6,13 @@ #include "Aufg3/Phonebook.h" #include "Aufg4/CrimeStats.h" #include "Aufg5/Mastermind.h" +#include "Aufg6/MineSweeper.h" int main() { // Aufg1Main(); // Aufg2Main(); // Aufg3Main(); // Aufg4Main(); - Aufg5Main(); + // Aufg5Main(); + Aufg6Main(); } diff --git a/Aufg5/Mastermind.h b/Aufg5/Mastermind.h index 4f076c2..9bd1e14 100644 --- a/Aufg5/Mastermind.h +++ b/Aufg5/Mastermind.h @@ -11,6 +11,8 @@ void Aufg5Main(); std::vector generateSecretCode(int size, int optionsPerDigit); +int getRandomNumberInRange(int min, int max); + std::vector getCodeGuessFromConsole(); std::vector convertStringToGuess(std::string &guessAsString); diff --git a/Aufg6/Bullshit_Bug.png b/Aufg6/Bullshit_Bug.png new file mode 100644 index 0000000..bf64636 Binary files /dev/null and b/Aufg6/Bullshit_Bug.png differ diff --git a/Aufg6/Bullshit_Bug2.png b/Aufg6/Bullshit_Bug2.png new file mode 100644 index 0000000..bbcd355 Binary files /dev/null and b/Aufg6/Bullshit_Bug2.png differ diff --git a/Aufg6/MineSweeper.cpp b/Aufg6/MineSweeper.cpp new file mode 100644 index 0000000..aa84d24 --- /dev/null +++ b/Aufg6/MineSweeper.cpp @@ -0,0 +1,79 @@ +#include +#include "../Aufg5/Mastermind.h" + +struct MineSweeperBoard { + std::string field[16][16]; + int bombCounter = 0; + + + void debugBoard(std::string character) { + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 16; j++) { + field[i][j] = character; + } + } + } + bool hasBomb(int i1, int i2) { + return field[i1][i2] == "x"; + } + void spreadBombs() { + while (bombCounter < 99) { + field[getRandomNumberInRange(0,15)][getRandomNumberInRange(0,15)] = "x"; + bombCounter++; + } + } + std::string countNeighbourBombs(int i, int j) { + i--; + j--; + int counter; + for (int k = 0; k < 3; k++) { + for (int l = 0; l < 3; l++) { + if ((i+k < 16) && (j+l < 16) && (i-l >= 0) && (j-l >= 0)) { + if (field[i+k][j+l] == "x") { + counter++; + } + } + } + } + return std::to_string(counter); + } + void calculateExplosiveNeighbours() { + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 16; j++) { + if (field[i][j] != "x") { + field[i][j] = countNeighbourBombs(i, j); + } + } + } + } + void printBoard() { + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 16; j++) { + std::cout << field[i][j] << " "; + } + std::cout << std::endl; + } + } +}; + + +void Aufg6Main() { + MineSweeperBoard board; + board.printBoard(); + std::cout << "Empty Board? ==============" << std::endl << std::endl; + + board.spreadBombs(); + board.printBoard(); + std::cout << "Bombed Board? ==============" << std::endl << std::endl; + + board.calculateExplosiveNeighbours(); + board.printBoard(); + std::cout << "Solved Board? ==============" << std::endl << std::endl; + + board.debugBoard("."); + board.field[14][14] = "x"; + board.field[13][13] = "x"; + board.field[13][15] = "x"; + board.calculateExplosiveNeighbours(); + board.printBoard(); +} diff --git a/Aufg6/MineSweeper.h b/Aufg6/MineSweeper.h new file mode 100644 index 0000000..b34fadd --- /dev/null +++ b/Aufg6/MineSweeper.h @@ -0,0 +1,10 @@ +// +// Created by DH10MBO on 15.11.2024. +// + +#ifndef MINESWEEPER_H +#define MINESWEEPER_H + +void Aufg6Main(); + +#endif //MINESWEEPER_H