Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//********************************************MINESWEEPER************************************************
//************PLEASE JUST TRY TO HELP ME WITH THE RECURSION.....CAUSE THE REST OF THE GAME IS JUST WHAT I NEED.....THANKS IN ADVANCE*********************
//HINTS
//MINES ARE INDICATED BY 9
//CLOSED CELLS BY 0-8 AND SPECIFICLY 0 INDICATES THE STILL CLOSED BUT EMTY CELL AND 1-8 THE STILL CLOSED BUT FILLED WITH THIS NUMBER CELL
//10-18 CELLS INDICATE THA OPENED CELLS...AND AS ABOVE...10 INCDICATES OPENED BUT EMTY CELL AND 11-18 OPENED BUT FILLED WITH NUMBER CELL...
//first try to make the recursive function that is going to check all the neighbour cells if they have a number from 1 to 8.
//if they have 0 then check their neighbours too!
//in order to differ the "opened" cells from the "closed" ones i need the function to add 10 to the cell
//so that if the cell contains 0 then it will become a 10(so that i am going to be able to show to the user that plays the game
//a "." that indicates the opened and emty cell)
//also if it contains 1-8 it will add 10 so that i am going to know that in my int array all the 1-8 are closed cells(numbered) and all the 11-18 cells
//are going to be the opened cells cointaining a number from 1-8(in order to show the right array to the user )
int **recursion(int **array,int x,int y,int n ,int m){
int i,j;
if((array[x][y]>=1)&&(array[x][y]<=8)){
array[x][y]=array[x][y]+10;
return array;
}
if(array[x][y]==0){
array[x][y]=array[x][y]+10;
for(i=-1;i<=1;i++){
for(j=-1;j<=1;j++){
if ((i==0)&&(j==0)){
continue;
}
if(x+i>n) x=x-1;
if(y+j>m) y=y-1;
if(x+i<0) x=x+1;
if(y+j<0) y=y+1;
return recursion(array,x+i,y+i,n,m);
}
}
}
}
//second try to make the recursive function...with the same characteristics.....
int **recursion2(int **array,int x,int y,int n ,int m){
if ((array[x][y]>=1)&&(array[x][y]<=8)){
array[x][y]=array[x][y]+10;
return array;
}
do{
if(x+1<=n){
array[x][y]=array[x][y]+10;
return recursion2(array,x+1,y,n,m);
}
if(y+1<=m){
array[x][y]=array[x][y]+10;
return recursion2(array,x,y+1,n,m);
}
if(x-1>0){
array[x][y]=array[x][y]+10;
return recursion2(array,x-1,y,n,m);
}
if(y-1>0){
array[x][y]=array[x][y]+10;
return recursion2(array,x,y-1,n,m);
}
if((x+1<=n)&&(y+1<=m)){
array[x][y]=array[x][y]+10;
return recursion2(array,x+1,y+1,n,m);
}
if((x-1>0)&&(y+1<=m)){
array[x][y]=array[x][y]+10;
return recursion2(array,x-1,y+1,n,m);
}
if((x-1>0)&&(y-1>0)){
array[x][y]=array[x][y]+10;
return recursion2(array,x-1,y-1,n,m);
}
if((x+1<=n)&&(y-1>0)){
array[x][y]=array[x][y]+10;
return recursion2(array,x+1,y-1,n,m);
}
} while((x+1<=n)||(y+1<=m)||(x-1>0)||(y-1>0)||((x+1<=n)&&(y+1<=m))||((x-1>0)&&(y-1>0))||((x-1>0)&&(y+1<=m))||((x+1<=n)&&(y-1>0)));
}