Arrays

closed account (yq52y60M)
Hi



Last edited on
Hey :) People are more like to help if you edit your post and put all your code between code tags. They are under the format section <>.

Ive never done one of these before but I'll edit the post if I find some things I can add. For now all I can say is, change void main() to int main() And I would also advice you to not use global variables, move them all into main.
closed account (yq52y60M)
New to the site so didn't know. Thanks
There have been a couple of people asking about minesweeper problems the past couple weeks. I particularly liked one of them where the board was a 2D array of ints, and whenever a tile was designated as a mine, then 10 was added to it. The eight tiles around it are all incremented by 1.
closed account (yq52y60M)
Can you help?
This is part of the code I wrote when responding to another minesweeper thread, using the implementation I just told you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    for (unsigned int i = 0; i < MINES; ++i)
    {        
        unsigned int row, col;
        
        do
        {
            row = disR(gen); //random
            col = disC(gen); //random
        } while (board[row][col] > 9);
        
        board[row][col] += 10;
        
        if (row > 0)
        {
            ++board[row - 1][col];
            if (col > 0)
                ++board[row - 1][col - 1];
            if (col < COLS - 1)
                ++board[row - 1][col + 1];
        }
        if (row < ROWS - 1)
        {
            ++board[row + 1][col];
            if (col > 0)
                ++board[row + 1][col - 1];
            if (col < COLS - 1)
                ++board[row + 1][col + 1];
        }
        if (col > 0)
            ++board[row][col - 1];
        if (col < COLS - 1)
            ++board[row][col + 1];
    }

There is no need for checking, because the tiles are all updated whenever a mine is added.
Last edited on
Topic archived. No new replies allowed.