Saper game please help

and what has this to do with Windows programming. It seems like a console program?

You can treat the board as either a 2-d array of n x n elements or as a single 1-d array of n * n elements and then access it as if it was a 2-d array.

There is also at least two ways of generating the board and displaying. One is to generate the board with the mines and then as displaying calculate the number of adjacent mines. The other is to update the adjacent mine info when the position of a mine is first determined.

When generating the random location of the mine, you can either generate 2 numbers if a 2-d array is used or one number if a 1-d array is used or the number is converted to a 2-d array if that is used.

To place the mines, you need a nested loop. The outer loop to loop k times. The inner to loop until a non-occupied position is found.

Do you know how to generate random numbers in C++ using std::uniform_int_distribution() - and how to seed the generator using std::random_device or other?

This will produce a set of (non-unique) random numbers:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <random>
#include <iostream>

std::mt19937 rng(std::random_device {}());

int main() {
	constexpr int rmin { 0 };
	constexpr int rmax { 10 };
	constexpr int required { 8 };

	std::uniform_int_distribution<> distrib(rmin, rmax);

	for (int i {}; i < required; ++i)
		std::cout << distrib(rng) << ' ';

	std::cout << '\n';
}



2 5 3 2 9 0 8 7

Yes, I do have a solution, multiple ones as a matter of fact, but you need to write the code. I won't just give the code to you without some effort on your part. This isn't my assignment.

I also found lots of code examples online by doing an internet search.


Looks like someone got booted for being a spammer. *sad*
Last edited on
Topic archived. No new replies allowed.