Minesweeper C++ [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've written the minesweeper game for C++, and the core game is complete.
There are three things I need to ask.
Currently, my mines are placed at random positions.. I was wondering if this is true for the actual game? Are the mines random or is their some specific pattern or algorithm for placing the mines.
When I play minesweeper on Win 7, I never see a 0. But in my program, there are cases when all 8 neighbors are non mines. What should I display then? I want the game to be as close to the Windows version as possible.
I think this may be related to 2 above, when I play on Win 7 sometimes when I click on a cell multiple cells are revealed. I want to do this in my program but I don't know the controlling logic behind it. I mean, when does this have to happen? And when it does happen, how do I know how many and which cells to open up?
On a related note, my current program is text based (in code blocks). Currently I know only C++. What do I need to learn to be able to make the game interactive?

The first guess is never a mine, so your generation algorithm must delay itself until this happens. As far as I am aware, mines are placed pseudo randomly.
When no adjacent mines are found on a guessed square, it reveals all adjacent squares.
On the versions I have played, when you left click and then right click together and when a location has a sufficient number of flags placed around it, it reveals all adjacent squares.

Yes they are placed at random. You need to make sure that you don't place two mines in the same spot.
A 0 is displayed as a blank in windows.
When you expose a square with no adjacent mines, it will automatically expose all 8 of those squares. If any of those are also zeros, they will be exposed also until an entire region is exposed.

Related

C++ Best way to "share screens" over socket [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
In my current app I need to share screens ala skype or discord, I'd prefer to not use external libs, but will if I have to.
So far I have been sending the screenshots in down-scaled bitmap form over TCP sockets and repainting the window every few milliseconds, this is of course an effort I knew was doomed from the start, is there any api that could save me?
Any help appreciated.
While I haven't implemented it myself, I believe that what's usually done is the screen is broken into 16x16 pixel blocks. You can keep the previous screenshot, take a new one, compare which blocks have changed and send only the 16x16 blocks that have changes in them.
You can further improve performance by having a change threshold. If fewer than x pixels have changed in a block, don't send yet. Or if the cumulative sum of the changes in a block (the difference between corresponding pixels) is below some threshold, don't send that block.
The blocks are also often compressed using a lossy compression scheme that really shrinks down the required size you need to send per block. The image blocks are often also sent in 4:2:2 mode, meaning you store the red and blue channels at half the resolution of the green channel. This is based on how the visual system works, but it explains why things that are pure red or pure blue sometimes get blockiness or fringing around them when screen sharing.

Draw a matrix of numbers as an image with C++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a quite specific question: I want to draw a matrix of numbers in a greyscale image. The higher the number the brighter the output. Is there a way to do that in a C++ programme without having dependencies to a graphic library like Qt?
I looked through some examples of ImageMagick, but I'm not sure how to implement its functions in C++.
Answer
In case someone stumbles upon this question:
a modified code of the example shown here was a handy and easy solution
It's hard without a library. SFML seems easy to use.
EDIT
Also you have 3 other questions hidden in your question:
1- To save an image you can use sf::image::saveToFile
2- To get brighter number for higher number: You need to normalize your numbers to [MinColorYouWant MaxColorYouWant] (for example: [128,255]). Thus the normalization value corresponding to each number will become the color of the number.
3- SFML uses RGBA images by default. Just set the RGB channels equal to make it look greyscale.
EDIT 2 : I've fixed the example normalization from [128,256] to [128,255].

Qt4 and SFML pitch recognition and processing [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am writing a program that displays a random natural note and waits for the user to play that note on the guitar. The audio input is processed to see if the correct pitch was played, and if it was, the next note is shown and the score of the user is updated. The idea is to teach basic guitar notes.
I intend to use SFML for audio processing and QT4 for the gui. I will have a widget derived from the relevant QObject and SFML classes.
Question: How do I detect the pitch of microphone input using SFML? Is it possible to simply store a part of the input in an sf::sound object and call it's getPitch() method?
Is it possible to simply store a part of the input in an sf::sound object and call it's getPitch() method?
GetPitch() from sf::SoundSource will return the value you used on SetPitch(pitch) or teh default 1.0f. It is to edit the sound, not to get information about it. I think the only way to do it is to get the array of sound samples and process it with some kind of algorithm. You can get this array with it:
sf::SoundBufferRecorder recorder;
recorder.Start();
// ...
recorder.Stop();
const sf::SoundBuffer& buffer = recorder.GetBuffer();
size_t sample_count = buffer.GetSamplesCount();
const sf::Int16* samples = buffer.GetSamples();
unsigned int samples_per_second = buffer.GetSampleRate();
As it turns out, SFML does not have any algorithms for detecting pitch built in. Thanks to LBg for getting my mind working in the right direction. SFML only provides the tools needed to record the sounds and store them in a buffer.
I found out that I can use a Fast Fourier transform to evaluate the buffer for a frequency. This frequency can then be compared to a list of known pitch frequencies, together with a pitch threshold.
While SFML doesn't have an fft algorithm built in, it does have the tools needed to get a sound buffer. I will have to check and see if this is the most cross-platform way of doing things.

Model slowing down the game - opengl [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a problem while running my game. The model that I import in the game is quite big, making the fps drop down. That's okay but when I get the camera off from the model, it still stays slow. As other games do, when looking at a high resolution model, the game slows down but when not looking at it, it gets faster. However my game stays slow all the time. Can anyone help me?
You need to implement clipping, so that you don't render the object (i.e. pass it through the graphics pipeline) when it's not visible.
There are many techniques and algorithms/data structures for this, ranging from manual view frustum-testing, to more advanced spatial-querying data structures (BSPs, quadtrees, octrees and so on).

Best way to learn about Direct X [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to begin looking at Direct X, but don't just want to try and throw myself into it. What are some good resources to get ones feet wet?
I highly recommend Toymaker's tutorials. Helped me greatly when I was first starting out with DX and was just as good as a reference later on.
The other thing to do would to set up some small projects that use DX that increase in difficulty as you go. If you'd like a starter list (from easy to hard):
Compiling using DX libraries (I always remeber having trouble linking the libraries correctly in Visual Studio).
Change background colour.
See a model on-screen.
Moving the model with input.
A camera.
Apply a texture to your model.
Add multiple models to your scene.
Add lighting.
Create your a simple rectangle model and display a texture on it.
Get comfortable with all that and then have a look at shaders, advanced lighting and animation.
There are quite a few books on directX, but there is so much freely available information on the web these days, I would just jump right in there.
A good place to start is just to do a youtube search for DirectX Tutorials. In my opinion, this is a fun and interesting way to get started learning a new dev skill.