<1>: returns the number of surrounding mines.
Function prototype: int round_num_mines (int I, int j );
For the original function, see: html "> http://www.bkjia.com/kf/201104/87210.html
Optimized
Algorithm function interface:
1Returns the number of surrounding mines.
/***************************************** ********************
Returns the number of surrounding mines.
Function prototype: int round_num_mines (int I, int j );
Parameter: int I, int j is the current Coordinate
Return Value Type: int, which returns the number of mines around the coordinate.
Returned values: (1) 1-8 represents 1-8 mines;
(2) If 0 is returned, no mines are found;
(3) return * representing the time when the coordinate is mine;
**************************************** ******************/
//////////////////////////////////////// //////////////
//
//Just wondering why the following two functions are notThe array may be out of bounds ???
//
//////////////////////////////////////// //////////////
CharRound_num_mines (IntI,IntJ)
{
If(Map [I] [j]= *)
{
Return *;
}
IntK= 0;
If(Map [I+1] [J]= *) K++;
If(Map [I+1] [J-1]= *) K++;
If(Map [I+1] [J+1]= *) K++;
If(Map [I] [j+1]= *) K++;
If(Map [I-1] [J]= *) K++;
If(Map [I-1] [J+1]= *) K++;
If(Map [I] [j-1]= *) K++;
If(Map [I-1] [J-1]= *) K++;
ReturnK;
}
*/
//Improved code:
(Improved Algorithm)
(1). First define a two-dimensional array:
Int