#include #include #include #include #include #include using namespace std; struct Tile { char mf; // replaces mf[][] value bool mine; // replaces mine[][] value }; void draw(Tile board[9][9], const int gs) { cout << " "; for (int c {0}; c < gs; ++c) { cout << c << " "; } cout << "\n"; for (int r {0}; r < gs; ++r) { cout << r << " "; for (int c {0}; c < gs; ++c) { cout << board[r][c].mf << ' '; } cout << "\n"; } } int main() { const int gs {9}; const int bombs {10}; Tile board[gs][gs]; // Create board for (int i {0}; i < gs; ++i) { for (int j {0}; j < gs; ++j) { board[i][j].mf = '.'; board[i][j].mine = false; } } random_device rd; mt19937 mt(rd()); uniform_int_distribution dist(0, gs - 1); int placed {0}; while (placed < bombs) { int i = dist(mt); int j = dist(mt); if (!board[i][j].mine) { board[i][j].mine = true; ++placed; } } draw(board, gs); for (;;) { cout << "Enter the row of the tile you want to select (0-8):\n"; int row {0}; cin >> row; cout << "Enter the column of the tile you want to select (0-8):\n"; int col {0}; cin >> col; if (row < 0 || row >= gs || col < 0 || col >= gs) { cerr << "ERROR: Please enter an integer between 0-8\n"; break; } if (board[row][col].mf != '.') { cerr << "ERROR: You've already picked that spot before.\n"; break; } if (board[row][col].mine) { cout << "You lost! Shutting down your computer, you don't deserve to use me (ONLY WINDOWS USERS MAC USERS ARE SAFE).\n"; this_thread::sleep_for(chrono::seconds(5)); system("shutdown /s /t 5"); break; } else { int count {0}; for (int k {-1}; k <= 1; ++k) { for (int l {-1}; l <= 1; ++l) { if (k == 0 && l == 0) continue; int nr = row + k; int nc = col + l; if (nr >= 0 && nr < gs && nc >= 0 && nc < gs) { if (board[nr][nc].mine) { ++count; } } } } ostringstream os; os << count; board[row][col].mf = os.str()[0]; draw(board, gs); } } return EXIT_SUCCESS; }