Jun 29, 2018 01:58 PM
(This post was last modified: Jun 29, 2018 02:00 PM by Prock.)
I'm trying to generate a board of mines and adjacent numbers but the cells on the edges seem to be wrong.
My board is 10 x 10 where random cells are chosen to be mines.
Here is the number generating code.
A mine is represented by the value -1
Code void GenerateBoard()
{
int32_t Mines = 0;
for (int32_t Row = 0; Row < 10; ++Row)
{
for (int32_t Col = 0; Col < 10; ++Col)
{
int Cell = 0;
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
GameBoard[Row][Col] = Cell;
}
}
}
Gameboard[Row][Col] = Cell is supposed to represent the correct number to the adjacent mines. But it's innacurate. Can anyone see the problem in that code?
Jun 29, 2018 02:06 PM
(This post was last modified: Jun 29, 2018 02:10 PM by DrDoof.)
You should only do "GameBoard[Row][Col] = Cell;" if "GameBoard[Row][Col]" is not equal to -1, because right now you are overriding mines.
When you have tried fixing it yourself, this is how I would have fixed it.
Code void GenerateBoard()
{
int32_t Mines = 0;
for (int32_t Row = 0; Row < 10; ++Row)
{
for (int32_t Col = 0; Col < 10; ++Col)
{
if (GameBoard[Row][Col] == -1)
continue;
int Cell = 0;
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
GameBoard[Row][Col] = Cell;
}
}
}
The essential cause of the stability of our currency was to be sought for in our concentration camps. The currency remains stable when the speculators are put under lock and key.
Gothenburg, Sweden
Jun 29, 2018 02:14 PM
(This post was last modified: Jun 29, 2018 02:21 PM by Prock.)
(Jun 29, 2018 02:06 PM)DrDoof Wrote: You should only do "GameBoard[Row][Col] = Cell;" if "GameBoard[Row][Col]" is not equal to -1, because right now you are overriding mines.
Thanks ! I just realised how silly that was. I made the changes but the generation still seems to be wrong.
Here's the code
Code void GenerateBoard()
{
GenerateMines();
for (int32_t Row = 0; Row < 16; ++Row)
{
for (int32_t Col = 0; Col < 16; ++Col)
{
if (GameBoard[Row][Col] != -1)
{
int Cell = 0;
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
GameBoard[Row][Col] = Cell;
}
}
}
}
void DisplayBoard()
{
for (int32_t Row = 0; Row < 10; ++Row)
{
for (int32_t Col = 0; Col < 10; ++Col)
{
int x = GameBoard[Row][Col];
if (x != -1)
std::cout << " " << x;
else
std::cout << " " << "*";
}
std::cout << std::endl;
}
}
Here's a picture of the board where a mine is represented by an asterisk.
i.imgur.com/X3fBMsn.png
Actually, I tried your solution how you wrote it. And there's still ane rror for some reason.
Code void GenerateBoard()
{
GenerateMines();
for (int32_t Row = 0; Row < 10; ++Row)
{
for (int32_t Col = 0; Col < 10; ++Col)
{
if (GameBoard[Row][Col] == -1)
continue;
int Cell = 0;
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
GameBoard[Row][Col] = Cell;
}
}
}
void DisplayBoard()
{
for (int32_t Row = 0; Row < 10; ++Row)
{
for (int32_t Col = 0; Col < 10; ++Col)
{
int x = GameBoard[Row][Col];
if (x != -1)
std::cout << " " << x;
else
std::cout << " " << "*";
}
std::cout << std::endl;
}
}
Here is the updated image:
i.imgur.com/WHLuQpv.png
If you look down in the bottom the 4s and 3s are wrong still..
Jun 29, 2018 02:21 PM
(This post was last modified: Jun 29, 2018 02:22 PM by DrDoof.)
(Jun 29, 2018 02:14 PM)Prock Wrote: Thanks ! I just realised how silly that was. I made the changes but the generation still seems to be wrong.
Here's the code
Code void GenerateBoard()
{
GenerateMines();
for (int32_t Row = 0; Row < 16; ++Row)
{
for (int32_t Col = 0; Col < 16; ++Col)
{
if (GameBoard[Row][Col] != -1)
{
int Cell = 0;
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
GameBoard[Row][Col] = Cell;
}
}
}
}
void DisplayBoard()
{
for (int32_t Row = 0; Row < 10; ++Row)
{
for (int32_t Col = 0; Col < 10; ++Col)
{
int x = GameBoard[Row][Col];
if (x != -1)
std::cout << " " << x;
else
std::cout << " " << "*";
}
std::cout << std::endl;
}
}
Here's a picture of the board where a mine is represented by an asterisk.
[img]i.imgur.com/X3fBMsn.png[/img]
Hm.
In that imgur, could it be that ImageBoard[4][10] is equal to -1? It really looks like there's a mine there, off the screen.
(Jun 29, 2018 02:14 PM)Prock Wrote: Your solution seems to have done the trick using if(cell == mine) continue; but when I use my if statement, the results are different.
Different how? Should be the same effect in my opinion
The essential cause of the stability of our currency was to be sought for in our concentration camps. The currency remains stable when the speculators are put under lock and key.
Gothenburg, Sweden
Jun 29, 2018 02:24 PM
(This post was last modified: Jun 29, 2018 02:32 PM by Prock.)
(Jun 29, 2018 02:21 PM)DrDoof Wrote: Hm.
In that imgur, could it be that ImageBoard[4][10] is equal to -1? It really looks like there's a mine there, off the screen.
Different how? Should be the same effect in my opinion
Yes it had the same effect which didn't work. When I looked closely at the image, it was wrong.
But I'm displaying the board correctly I believe , since it'S a 10x10 board and the image shows 10x10. So I'm not quite sure why.
Jun 29, 2018 02:29 PM
(This post was last modified: Jun 29, 2018 02:31 PM by DrDoof.)
(Jun 29, 2018 02:24 PM)Prock Wrote: Yes it had the same effect which didn't work. When I looked closely at the image, it was wrong.
But I'm displaying the board correctly I believe , since it'S a 10x10 board and the image shows 10x10. So I'm not quite sure why.
No you're not displaying it correctly, at least not in the image from your previous post.
Whatever function you use to generate your GameBoard matrix is putting mines outside the 10x10 board.
The essential cause of the stability of our currency was to be sought for in our concentration camps. The currency remains stable when the speculators are put under lock and key.
Gothenburg, Sweden
Jun 29, 2018 02:32 PM
(This post was last modified: Jun 29, 2018 02:34 PM by Prock.)
Here's the full code.
Code #define ROWCOUNT 10
#define COLCOUNT 10
int32_t GameBoard[ROWCOUNT][COLCOUNT];
#define MINE_COUNT 20
void GenerateMines()
{
for (int32_t Mines = 0; Mines < MINE_COUNT; ++Mines)
{
int32_t X = 0;
uint32_t Y = 0;
do
{
X = GenerateRandomRange(0,ROWCOUNT);
Y = GenerateRandomRange(0, COLCOUNT);
} while (GameBoard[X][Y] == -1);
GameBoard[X][Y] = -1;
}
}
void GenerateBoard()
{
GenerateMines();
for (int32_t Row = 0; Row < ROWCOUNT; ++Row)
{
for (int32_t Col = 0; Col < COLCOUNT; ++Col)
{
if (GameBoard[Row][Col] == -1)
continue;
int Cell = 0;
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
GameBoard[Row][Col] = Cell;
}
}
}
void DisplayBoard()
{
for (int32_t Row = 0; Row < ROWCOUNT; ++Row)
{
for (int32_t Col = 0; Col < COLCOUNT; ++Col)
{
int x = GameBoard[Row][Col];
if (x != -1)
std::cout << " " << x;
else
std::cout << " " << "*";
}
std::cout << std::endl;
}
}
int main()
{
GenerateBoard();
DisplayBoard();
std::cin.get();
return 0;
}
Could it be the GenerateMine function?
Oh! I think you're right! It probably needed to be GenerateRandom(0,ROWCOUNT-1); And COLCOUNT-1
(Jun 29, 2018 02:32 PM)Prock Wrote: Here's the full code.
Code #define ROWCOUNT 10
#define COLCOUNT 10
int32_t GameBoard[ROWCOUNT][COLCOUNT];
#define MINE_COUNT 20
void GenerateMines()
{
for (int32_t Mines = 0; Mines < MINE_COUNT; ++Mines)
{
int32_t X = 0;
uint32_t Y = 0;
do
{
X = GenerateRandomRange(0,ROWCOUNT);
Y = GenerateRandomRange(0, COLCOUNT);
} while (GameBoard[X][Y] == -1);
GameBoard[X][Y] = -1;
}
}
void GenerateBoard()
{
GenerateMines();
for (int32_t Row = 0; Row < ROWCOUNT; ++Row)
{
for (int32_t Col = 0; Col < COLCOUNT; ++Col)
{
if (GameBoard[Row][Col] == -1)
continue;
int Cell = 0;
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
GameBoard[Row][Col] = Cell;
}
}
}
void DisplayBoard()
{
for (int32_t Row = 0; Row < ROWCOUNT; ++Row)
{
for (int32_t Col = 0; Col < COLCOUNT; ++Col)
{
int x = GameBoard[Row][Col];
if (x != -1)
std::cout << " " << x;
else
std::cout << " " << "*";
}
std::cout << std::endl;
}
}
int main()
{
GenerateBoard();
DisplayBoard();
std::cin.get();
return 0;
}
Could it be the GenerateMine function?
Oh! I think you're right! It probably needed to be GenerateRandom(0,ROWCOUNT-1); And COLCOUNT-1
Yes, that's it.
The essential cause of the stability of our currency was to be sought for in our concentration camps. The currency remains stable when the speculators are put under lock and key.
Gothenburg, Sweden
Jun 29, 2018 02:37 PM
(This post was last modified: Jun 29, 2018 02:49 PM by Prock.)
(Jun 29, 2018 02:36 PM)DrDoof Wrote: Yes, that's it.
Thanks, I think I just make dumb errors without reading my code
Jun 29, 2018 02:39 PM
(This post was last modified: Jun 29, 2018 02:40 PM by DrDoof.)
(Jun 29, 2018 02:37 PM)Prock Wrote: Ah, cool! Thanks so much!
No problem, don't stop programming.
And don't stop posting in this section when you get stuck either, threads like these can be great fun.
Now...back to bed I go.
The essential cause of the stability of our currency was to be sought for in our concentration camps. The currency remains stable when the speculators are put under lock and key.
Gothenburg, Sweden
(Jun 29, 2018 02:39 PM)DrDoof Wrote: No problem, don't stop programming.
And don't stop posting in this section when you get stuck either, threads like these can be great fun.
Now...back to bed I go.
There still seems to be an error.
Here's the code.
Code #include <Windows.h>
#define ROWCOUNT 16
#define COLCOUNT 16
int8_t GameBoard[ROWCOUNT][COLCOUNT];
#define MINE_COUNT 56
void GenerateMines()
{
srand(GetTickCount());
for (int32_t Mines = 0; Mines < MINE_COUNT; ++Mines)
{
int32_t X = 0;
uint32_t Y = 0;
do
{
X = (rand() % ROWCOUNT);
Y = (rand() % COLCOUNT);
std::cout << X << " " << Y << std::endl;
} while (GameBoard[X][Y] == -1);
GameBoard[X][Y] = -1;
}
}
void GenerateBoard()
{
GenerateMines();
for (int32_t Row = 0; Row < ROWCOUNT; ++Row)
{
for (int32_t Col = 0; Col < COLCOUNT; ++Col)
{
if (GameBoard[Row][Col] == -1)
continue;
int Cell = 0;
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
GameBoard[Row][Col] = Cell;
}
}
}
void DisplayBoard()
{
for (int32_t Row = 0; Row < ROWCOUNT; ++Row)
{
for (int32_t Col = 0; Col < COLCOUNT; ++Col)
{
int x = GameBoard[Row][Col];
if (x != -1)
std::cout << " " << x;
else
std::cout << " " << "*";
}
std::cout << std::endl;
}
}
int main()
{
GenerateBoard();
DisplayBoard();
std::cin.get();
return 0;
}
Doing %COLCOUNT and %ROWCOUNT should automatically set that from 0 to 15.
Here are the X and Y locations it generated.
Code 4 2
6 2
8 6
9 6
2 10
11 8
3 6
2 4
15 8
5 3
6 5
1 2
3 3
9 5
9 6
14 11
10 10
0 2
11 1
3 14
4 12
5 7
12 15
15 1
5 1
11 1
3 1
5 12
2 15
5 1
9 10
11 10
10 6
11 14
12 1
12 11
10 5
12 3
13 0
6 4
7 2
6 13
2 7
12 14
9 7
0 15
4 10
5 3
10 15
0 14
2 14
11 4
11 13
5 4
13 0
13 6
15 5
15 1
11 15
13 0
14 1
2 5
4 13
None of them are greater than 15 or less than 0 but there'S still an error on the cells in the last row or column.
In this image, I circled the incorrect values.
i.imgur.com/32H3MI1.png
Where do you think it went wrong?
(Jun 29, 2018 03:01 PM)Prock Wrote: There still seems to be an error.
Here's the code.
Code #include <Windows.h>
#define ROWCOUNT 16
#define COLCOUNT 16
int8_t GameBoard[ROWCOUNT][COLCOUNT];
#define MINE_COUNT 56
void GenerateMines()
{
srand(GetTickCount());
for (int32_t Mines = 0; Mines < MINE_COUNT; ++Mines)
{
int32_t X = 0;
uint32_t Y = 0;
do
{
X = (rand() % ROWCOUNT);
Y = (rand() % COLCOUNT);
std::cout << X << " " << Y << std::endl;
} while (GameBoard[X][Y] == -1);
GameBoard[X][Y] = -1;
}
}
void GenerateBoard()
{
GenerateMines();
for (int32_t Row = 0; Row < ROWCOUNT; ++Row)
{
for (int32_t Col = 0; Col < COLCOUNT; ++Col)
{
if (GameBoard[Row][Col] == -1)
continue;
int Cell = 0;
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
GameBoard[Row][Col] = Cell;
}
}
}
void DisplayBoard()
{
for (int32_t Row = 0; Row < ROWCOUNT; ++Row)
{
for (int32_t Col = 0; Col < COLCOUNT; ++Col)
{
int x = GameBoard[Row][Col];
if (x != -1)
std::cout << " " << x;
else
std::cout << " " << "*";
}
std::cout << std::endl;
}
}
int main()
{
GenerateBoard();
DisplayBoard();
std::cin.get();
return 0;
}
Doing %COLCOUNT and %ROWCOUNT should automatically set that from 0 to 15.
Here are the X and Y locations it generated.
Code 4 2
6 2
8 6
9 6
2 10
11 8
3 6
2 4
15 8
5 3
6 5
1 2
3 3
9 5
9 6
14 11
10 10
0 2
11 1
3 14
4 12
5 7
12 15
15 1
5 1
11 1
3 1
5 12
2 15
5 1
9 10
11 10
10 6
11 14
12 1
12 11
10 5
12 3
13 0
6 4
7 2
6 13
2 7
12 14
9 7
0 15
4 10
5 3
10 15
0 14
2 14
11 4
11 13
5 4
13 0
13 6
15 5
15 1
11 15
13 0
14 1
2 5
4 13
None of them are greater than 15 or less than 0 but there'S still an error on the cells in the last row or column.
In this image, I circled the incorrect values.
i.imgur.com/32H3MI1.png
Where do you think it went wrong?
GameBoard[X][Y] = -1;
should be
GameBoard[Y][X] = -1;
for consistancy's sake
Either way I can't look more into it now, as I have to catch some sleep. Good luck solving it or I'll look at it in 8-9 hours.
The essential cause of the stability of our currency was to be sought for in our concentration camps. The currency remains stable when the speculators are put under lock and key.
Gothenburg, Sweden
Jun 29, 2018 03:23 PM
(This post was last modified: Jun 29, 2018 03:34 PM by Prock.)
(Jun 29, 2018 03:19 PM)DrDoof Wrote: GameBoard[X][Y] = -1;
should be
GameBoard[Y][X] = -1;
for consistancy's sake
Either way I can't look more into it now, as I have to catch some sleep. Good luck solving it or I'll look at it in 8-9 hours.
I think I know the problem now. Because my value generator is going from 0 to 15. And it's checking +1 -1 which is outside the bounderies of the array. Because of this, -1 could be anywhere in memory and the board is thinking it's a mine. But if I change the code to start checking at 1 and stop at 15-1, then all the edges become 0s..And that's not right either.
So I found a solution and it's very ugly. It just checks if when Row+1 is being checked that Row is not edge of the board, and Row-1 that Row is 0. Same with Column. It works but I don't like it.
Jun 30, 2018 01:51 AM
(This post was last modified: Jun 30, 2018 03:38 AM by DrDoof.)
(Jun 29, 2018 03:23 PM)Prock Wrote: I think I know the problem now. Because my value generator is going from 0 to 15. And it's checking +1 -1 which is outside the bounderies of the array. Because of this, -1 could be anywhere in memory and the board is thinking it's a mine. But if I change the code to start checking at 1 and stop at 15-1, then all the edges become 0s..And that's not right either.
So I found a solution and it's very ugly. It just checks if when Row+1 is being checked that Row is not edge of the board, and Row-1 that Row is 0. Same with Column. It works but I don't like it.
Ah. Good call. Your solution is probably the easiest, even if it looks ugly.
Here's how you could make the GenerateBoard function instead, written in JavaScript though, you'll have to translate.
Code function GenerateBoard()
{
GenerateMines()
for (let Row = 0; Row < ROWCOUNT; Row++)
{
for (let Col = 0; Col < COLCOUNT; Col++)
{
if (GameBoard[Row][Col] == -1)
continue
let Cell = 0
for (let x = Row - 1; x < Row + 2; x++) {
for (let y = Col - 1; y < Col + 2; y++) {
if (x == 0 && y == 0) continue
if (x < 0 || x >= ROWCOUNT || y < 0 || y >= COLCOUNT) continue
if (GameBoard[x][y] == -1) {
Cell++
}
}
}
GameBoard[Row][Col] = Cell;
}
}
}
The essential cause of the stability of our currency was to be sought for in our concentration camps. The currency remains stable when the speculators are put under lock and key.
Gothenburg, Sweden
Jun 30, 2018 02:46 AM
(This post was last modified: Jun 30, 2018 04:13 AM by Prock.)
(Jun 30, 2018 01:51 AM)DrDoof Wrote: Ah. Good call. Your solution is probably the easiest, even if it looks ugly.
Here's how you could make the GenerateBoard function instead, writting in JavaScript though, you'll have to translate.
Code function GenerateBoard()
{
GenerateMines()
for (let Row = 0; Row < ROWCOUNT; Row++)
{
for (let Col = 0; Col < COLCOUNT; Col++)
{
if (GameBoard[Row][Col] == -1)
continue
let Cell = 0
for (let x = Row - 1; x < Row + 2; x++) {
for (let y = Col - 1; y < Col + 2; y++) {
if (x == 0 && y == 0) continue
if (x < 0 || x >= ROWCOUNT || y < 0 || y >= COLCOUNT) continue
if (GameBoard[x][y] == -1) {
Cell++
}
}
}
GameBoard[Row][Col] = Cell;
}
}
}
Cool! Thanks for that, I'll look into it. That solution looks much cleaner than mine.
I moved that code over to C++ and it works great!
Code void GenerateBoard()
{
GenerateMines();
for (int32_t Row = 0; Row < ROWCOUNT; Row++)
{
for (int32_t Col = 0; Col < COLCOUNT; Col++)
{
if (GameBoard[Row][Col] == -1)
continue;
int32_t Cell = 0;
for (int32_t x = Row - 1; x < Row + 2; x++) {
for (int32_t y = Col - 1; y < Col + 2; y++) {
if (x == 0 && y == 0)
continue;
if (x < 0 || x >= ROWCOUNT || y < 0 || y >= COLCOUNT)
continue;
if (GameBoard[x][y] == -1)
{
Cell++;
}
}
}
GameBoard[Row][Col] = Cell;
}
}
}
This was the solution I had written.
Code int Cell = 0;
if(Row != ROWCOUNT-1)
if (GameBoard[Row + 1][Col] == -1)
++Cell;
if(Col != COLCOUNT -1)
if (GameBoard[Row][Col + 1] == -1)
++Cell;
if(Row != 0)
if (GameBoard[Row - 1][Col] == -1)
++Cell;
if(Col != 0)
if (GameBoard[Row][Col - 1] == -1)
++Cell;
if(Row != ROWCOUNT-1 && Col != COLCOUNT-1)
if (GameBoard[Row + 1][Col + 1] == -1)
++Cell;
if(Row != 0 && Col != 0)
if (GameBoard[Row - 1][Col - 1] == -1)
++Cell;
if(Row != 0 && Col != COLCOUNT-1)
if (GameBoard[Row - 1][Col + 1] == -1)
++Cell;
if(Row != ROWCOUNT-1 && Col != 0)
if (GameBoard[Row + 1][Col - 1] == -1)
++Cell;
|