hey, i am trying to write the code for a function to reveal the tiles with no bombs around them around the selected code. i have written the code that can reveal the bombs around one tile with the range of 1 and i can use this exact function for all the tiles around the selected one again but that is too much work and doesn't make the whole code portable.
What I have tried:
so what i have done is created two arrays, one of them is the mine field which the user can't make any changes to "hidden_board" and the other one is "my_board" which all of the changes are applied to this array and here are the functions that i have written:
void reveal_tiles_without_bombs_prime(int x, int y, int my_board[][9], int hidden_board[][9]){
--x;
--y;
if(x>=0 && x<9 && y>=0 && y<9){
if (my_board[x][y]==10){
if (number_of_bombs_around(x,y,hidden_board)==0){
if (y+1<9){
if (number_of_bombs_around(x+1, y+1+1, hidden_board)==0)
my_board[x][y+1]= 0;
}
if (y-1>=0){
if (number_of_bombs_around(x+1, y-1+1, hidden_board)==0)
my_board[x][y-1]= 0;
}
if (x-1>=0){
if (number_of_bombs_around(x-1+1, y+1, hidden_board)==0)
my_board[x-1][y]= 0;
}
if (x+1<9){
if (number_of_bombs_around(x+1+1, y+1, hidden_board)==0)
my_board[x+1][y]= 0;
}
if ((y-1>=0) && (x-1>=0)){
if (number_of_bombs_around(x-1+1, y-1+1, hidden_board)==0)
my_board[x-1][y-1]= 0;
}
if ((y+1<9) && (x-1>=0)){
if (number_of_bombs_around(x-1+1, y+1+1, hidden_board)==0)
my_board[x-1][y+1]= 0;
}
if ((y-1>=0) && (x+1<9)){
if (number_of_bombs_around(x+1+1, y-1+1, hidden_board)==0)
my_board[x+1][y-1]= 0;
}
if ((y+1<9) && (x+1<9)){
if (number_of_bombs_around(x+1+1, y+1+1, hidden_board)==0)
my_board[x+1][y+1]= 0;
}
}
}
}
}
int the my_board array i use 10 for an unrevealed tile which is not a bomb and numbers 0 to 8 for number of bombs around a revealed tile and 11 for an unrevealed bomb and the number_of_bombs_around is an another function that returns the number of bombs around the given tile. so this function is actually called only one time in the else part:
if (number_of_bombs_around(x,y, hidden_board)!=0){
my_board[x-1][y-1]= number_of_bombs_around(x,y,my_board);
draw_mine_field(my_board);
}
else{
reveal_tiles_without_bombs_prime(x,y,my_board, hidden_board);
my_board[x-1][y-1]= 0;
and after using the prime version i have to use the function below to reveal all of the tiles with no bombs around them around the tile that is given:
void reveal_tiles_without_bombs(int x, int y, int my_board[][9], int hidden_board[][9]){
--x;
--y;
if(x>=0 && x<9 && y>=0 && y<9){
if (my_board[x][y]==0){
if (y+1<9){
if (number_of_bombs_around(x+1, y+1+1, hidden_board)==0)
my_board[x][y+1]= 0;
}
if (y-1>=0){
if (number_of_bombs_around(x+1, y-1+1, hidden_board)==0)
my_board[x][y-1]= 0;
}
if (x-1>=0){
if (number_of_bombs_around(x-1+1, y+1, hidden_board)==0)
my_board[x-1][y]= 0;
}
if (x+1<9){
if (number_of_bombs_around(x+1+1, y+1, hidden_board)==0)
my_board[x+1][y]= 0;
}
if ((y-1>=0) && (x-1>=0)){
if (number_of_bombs_around(x-1+1, y-1+1, hidden_board)==0)
my_board[x-1][y-1]= 0;
}
if ((y+1<9) && (x-1>=0)){
if (number_of_bombs_around(x-1+1, y+1+1, hidden_board)==0)
my_board[x-1][y+1]= 0;
}
if ((y-1>=0) && (x+1<9)){
if (number_of_bombs_around(x+1+1, y-1+1, hidden_board)==0)
my_board[x+1][y-1]= 0;
}
if ((y+1<9) && (x+1<9)){
if (number_of_bombs_around(x+1+1, y+1+1, hidden_board)==0)
my_board[x+1][y+1]= 0;
}
}
}
}
so my question is that can i use a function to call reveal_tiles_without_bombs for all of the tiles around the chosen one until there are no more ? sorry for the long codes :)