Hie. I am beginner learner of c++. This code executes the game minewsweeper, but i should make from it the two player game. I have no any ideas. Cpuld u give some advices
std::vector<std::vector<Cell>> nodes {}; // the minefield matrix
public:
explicit MineField(int x, int y, int m)
: side_x{x}, side_y{y}, mines{m}, engine(this->seeder()), dist(0, (side_x*side_y))
{
if (mines > side_x*side_y) {throw std::runtime_error("More mines than cells");}
if (mines <= 0 || side_x <= 0 || side_y <= 0) {
throw std::runtime_error("Cannot be zero or less");
}
if (check_end()) {
std::cout << "\n\nYOU WIN!!!\n\n";
return false;
}
return true;
}
private:
void create_nodes(unsigned x, unsigned y)
// populates the matrix with default values
{
using sz_t = std::vector<std::vector<Cell>>::size_type;
nodes.reserve(y);
for (sz_t i = 0; i < y; ++i) {
nodes.emplace_back(std::vector<Cell>(x));
}
}
void insert_mines() // insert n random mines in the matrix
{
int a, b, counter = 0;
while (counter < mines) {
a = dist(engine) % side_y;
b = dist(engine) % side_x;
if (!nodes[a][b].is_mine) {
nodes[a][b].is_mine = true;
++counter;
}
}
}
inline bool is_valid_coord(int a, int b) const noexcept
// checks if is within the matrix
{
if (a >= 0 && a < side_y && b >= 0 && b < side_x) {
return true;
}else {return false;}
}
void fill_cells()
/* This function populates the cell values according to
the neighbouring mines */
{
using sz_t = std::vector<std::vector<Cell>>::size_type;
for (sz_t i=0; i<nodes.size(); ++i) {
for (sz_t j=0; j<nodes[0].size(); ++j) {
for (int b=-1; b<=1; ++b) {
for (int a=-1; a<=1; ++a) {
if (is_valid_coord(b+i, a+j)) {
if (nodes[b+i][a+j].is_mine) {
nodes[i][j].val++;
}
}
}
}
}
}
}
void open_zeroes(int i, int j)
{ // open all adjacent zeroes (Breadth First Search algorithm)
using namespace std;
inline void parse_input(std::string& s, int& x, int& y)
{
std::stringstream ss {s};
char c;
ss >> x >> c >> y;
ss.clear();
}
int main()
{ /*The 3 levels that are used for time-world-rankings are:
8x8_10 (WR 0.31 s but luck too much involved)
16x16_40 (WR 7.03 s)
16x30_99 (WR 31.13 s)
*/
using namespace std;