#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(); }