Hi guys im making a minesweeper game and im trying to implement a function that finds the certain blank spaces next to the mines so i can add the number. i have to Use numbers from 1-8 to mark other squares that have that number of mines adjacent to them. Squares that don't have adjacent mines are marked as BLANK. Code: --------------------------- * 1 2 3 4 5 6 * +---+---+---+---+---+---+ [ EXAMPLE 1] * a | M | M | 1 | | | | * +---+---+---+---+---+---+ * b | 2 | 2 | 1 | | | | * +---+---+---+---+---+---+ * c | | | 1 | 1 | 1 | | * +---+---+---+---+---+---+ * d | | | 2 | M | 2 | | * +---+---+---+---+---+---+ * e | | | 3 | M | 4 | 1 | * +---+---+---+---+---+---+ * f | | | 2 | M | M | 1 | * +---+---+---+---+---+---+ * --------------------------- Code: #define BLANK "" #define MINE 'M' void placeMines(char minefield[MAX_GRID][MAX_GRID], unsigned size) { double result; double sizetotal; double roundUp; int seed; int range; int NoMines; int TotalMine; int i=0; int j=0; int a=0; int b=0; int count; char mineChar = MINE; srand(time(NULL)); /* square root the grid number*/ sizetotal = size * size; /* result is the sizetotal * 0.6*/ result = (float)(float)sizetotal * MINE_DENSITY; /*rouding the number up 5.7 up to 6*/ roundUp = ceil(result); /* cast it to an int to get no decimal places*/ printf("NO MINES:%d\n",(int) roundUp); for(i=0; i<roundUp; i++) { int row, col; row = rand() % size; col = rand() % size; printf("%c %d %d\n",mineChar, row, col); minefield [row][col]= MINE; printf("\n"); } for(i=0; i<size; i++) { for(j=0; j<size; j++) { if(minefield[i][j]==BLANK) { if(j==0) { for(a=0; a<size; a++) { if(minefield[i][j]==MINE) { count++; } } }/* end of outter loop*/ } } } printGridMineSize(minefield, size); }
As you have the array to hold whether its M or N then you can go ahead and see fo each N whats the value in the array on each side and get the no for that N.