Fix Bug and add second counting variant
This commit is contained in:
parent
e95f7f74d2
commit
775144421e
@ -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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user