diff --git a/Aufg6/MineSweeper.cpp b/Aufg6/MineSweeper.cpp index 4ae7ce3..1a941f6 100644 --- a/Aufg6/MineSweeper.cpp +++ b/Aufg6/MineSweeper.cpp @@ -26,6 +26,7 @@ struct MineSweeperBoard { } } } + std::string countNeighbourBombs(int i, int j) { i--; j--; @@ -33,7 +34,8 @@ struct MineSweeperBoard { // int counter; // Not setting this nerd to 0 can cause a bug 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 ((i+k < 16) && (j+l < 16) && (i+l >= 0) && (j+l >= 0)) { + // if ((i+k < 16) && (j+l < 16) && (i-l >= 0) && (j-l >= 0)) { if (field[i+k][j+l] == "x") { counter++; } @@ -42,6 +44,22 @@ struct MineSweeperBoard { } return std::to_string(counter); } + + std::string countNeighbourBombsBetter(int i, int j) { + int counter = 0; + // int counter; // Not setting this nerd to 0 can cause a bug + for (int k = -1; k <= 1; k++) { + for (int l = -1; l <= 1; 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++) { @@ -51,6 +69,7 @@ struct MineSweeperBoard { } } } + void printBoard() { for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) {