#include #include using namespace std; #define UNCOV 4 #define FLG 5 #define COV 6 #define MINE 9 int board[40][40], flags[40][40], visited[40][40]; int getInfo(int rows, int cols, int x, int y, int type) { int count = 0; if( x-1 >= 0 ){ if( y-1 >= 0 && board[x-1][y-1] == type) { count++; } if( y+1 < rows && board[x-1][y+1] == type) {count++; } if(board[x-1][y] == type) { count++; } } if( x+1 < cols ){ if( y-1 >= 0 && board[x+1][y-1] == type) { count++; } if( y+1 < rows && board[x+1][y+1] == type) {count++; } if(board[x+1][y] == type) { count++; } } if( y-1 >= 0 ){ if(board[x][y-1] == type) { count++; } } if( y+1 < rows ){ if(board[x][y+1] == type) { count++; } } return count; } int checkSquares(int rows, int cols) { int count=0; for(int i=0; i= 0 ) if(flags[x-1][y] != FLG ) { flags[x-1][y] = UNCOV; } if( x+1 < cols ) if(flags[x+1][y] != FLG) { flags[x+1][y]= UNCOV; } if( y-1 >= 0 ) if(flags[x][y-1] != FLG) { flags[x][y-1] = UNCOV; } if( y+1 < rows ) if(flags[x][y+1] != FLG) { flags[x][y+1] = UNCOV;} } if( f + c == m) { //flag all covered cells if( x-1 >= 0 ) if(flags[x-1][y] != UNCOV ) { flags[x-1][y] = FLG; } if( x+1 < cols ) if(flags[x+1][y] != UNCOV) { flags[x+1][y]= FLG; } if( y-1 >= 0 ) if(flags[x][y-1] != UNCOV) { flags[x][y-1] = FLG; } if( y+1 < rows ) if(flags[x][y+1] != UNCOV) { flags[x][y+1] = FLG;} } for(int i=0; i> rows; in >> cols; if( rows == 0 || cols == 0) { exit(0); } cout << rows << " -- " << cols << endl; for(int i=0; i> temp; int a; switch(temp) { case '.': a=0; break; case 'M': a=MINE; break; default: a = (int) temp; } board[i][j] = a; } }//end nested for //debug for(int i=0; i