Problem Statement
Write a class MineField, which contains a method getMineField. getMineField takes a
The String passed to the method will be in the following format (quotes added for clarity):
- "(r0,c0)(r1,c1)...(rN,cN)"
Each pair of parentheses holds the coordinates of a mine in (row, column) format. Counting begins at 0, not 1. Therefore, (0,0) represents the upper-left corner, and (8,8) represents the bottom-right corner. For example, suppose Bob randomly generated the following locations:
- "(0,0)(1,0)(2,0)(3,0)(4,0)"
{ "M20000000", "M30000000", "M30000000", "M30000000", "M20000000", "110000000", "000000000", "000000000", "000000000" }There are 5 mines (symbolized by "M") located straight down the first column. Two spots on the board border 1 mine; two spots border 2 mines; and three spots border 3 mines. All other spots on the board border no mines.
Definition
- Class:
- MineField
- Method:
- getMineField
- Parameters:
- String
- Returns:
- String[]
- Method signature:
- String[] getMineField(String mineLocations)
- (be sure your method is public)
Constraints
- mineLocations will contain between 0 and 50 characters, inclusive
- mineLocations will contain between 0 and 10 mines, inclusive
- mineLocations will be in the format "(r0,c0)(r1,c1)...(rN,cN)" where each r# and c# is a digit between '0' and '8', inclusive
- mineLocations will not contain duplicate locations
Examples
"(0,0)(1,0)(2,0)(3,0)(4,0)"
Returns: { "M20000000", "M30000000", "M30000000", "M30000000", "M20000000", "110000000", "000000000", "000000000", "000000000" }
This is the example from above.
"(0,0)(0,8)(8,0)(8,8)"
Returns: { "M1000001M", "110000011", "000000000", "000000000", "000000000", "000000000", "000000000", "110000011", "M1000001M" }
There is a mine in each corner of the board. There are twelve spots that border exactly 1 mine. All other spots border no mines.
"(3,2)(3,3)(3,4)(4,2)(4,4)(5,2)(5,3)(5,4)(7,4)(6,7)"
Returns: { "000000000", "000000000", "012321000", "02MMM2000", "03M8M3000", "02MMM2111", "0124321M1", "0001M1111", "000111000" }
""
Returns: { "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000" }
Don't forget the empty case.
"(6,0)(6,8)(6,6)(8,3)(1,0)(5,4)(6,3)(4,4)(6,4)(1,5)"
Returns: { "110011100", "M1001M100", "110011100", "000111000", "0002M2000", "1114M4121", "M11MM3M2M", "112332121", "001M10000" }
"(0,0)(7,1)(0,4)(7,7)(7,0)(0,1)(4,8)(7,6)(6,4)(7,2)"
Returns: { "MM11M1000", "221111000", "000000000", "000000011", "00000001M", "000111011", "2322M2221", "MMM212MM1", "232101221" }
"(0,8)(2,3)(4,0)(1,0)(4,2)(1,5)(0,4)(6,8)(0,5)(8,1)"
Returns: { "1101MM21M", "M1124M211", "111M21100", "122210000", "M2M100000", "121100011", "00000001M", "111000011", "1M1000000" }
"(5,2)(6,5)(3,1)(4,0)(0,0)(6,7)(7,0)(8,1)"
Returns: { "M10000000", "110000000", "111000000", "2M1000000", "M32100000", "12M111211", "12111M2M1", "M21011211", "2M1000000" }
"(6,7)(2,0)(0,2)(3,2)(3,3)(8,6)(3,4)(5,2)"
Returns: { "01M100000", "121100000", "M22321000", "12MMM1000", "023421000", "01M100111", "0111001M1", "000001221", "000001M10" }
"(0,2)(8,5)(8,3)(2,1)(1,6)(0,1)(3,8)(2,4)(3,2)(3,4)"
Returns: { "1MM101110", "233212M10", "1M23M3121", "12M3M201M", "011211011", "000000000", "000000000", "001121100", "001M2M100" }
"(3,6)(6,6)(5,4)(1,5)(3,4)(7,3)(2,6)(4,6)(8,8)(0,7)"
Returns: { "0000112M1", "00001M321", "000124M20", "0001M4M30", "000224M20", "0001M3220", "001222M10", "001M11121", "00111001M" }
"(2,7)(4,5)(6,5)(3,8)(8,7)(4,3)"
Returns: { "000000000", "000000111", "0000001M2", "00112122M", "001M2M111", "001132200", "00001M100", "000011211", "0000001M1" }
"(1,5)(0,6)(5,5)(3,2)(0,4)(2,0)(6,6)(2,7)(8,5)(8,4)"
Returns: { "0001M3M10", "11012M321", "M211112M1", "12M100111", "011111100", "00001M210", "000012M10", "000123210", "0001MM100" }
"(2,4)(3,5)(0,7)(4,4)(6,6)(3,4)(4,3)"
Returns: { "0000001M1", "000111111", "0002M3100", "0014MM100", "001MM3100", "001222110", "000001M10", "000001110", "000000000" }
"(7,6)(6,3)(4,3)(4,2)(5,2)(0,5)(3,0)(3,8)"
Returns: { "00001M100", "000011100", "110000011", "M2221001M", "13MM10011", "02M420000", "012M11110", "001111M10", "000001110" }
"(7,5)(7,3)(6,3)(7,8)(7,1)(6,1)(5,3)(7,4)"
Returns: { "000000000", "000000000", "000000000", "000000000", "001110000", "113M20000", "2M5M52111", "2M4MMM11M", "112232111" }
"(4,4)(2,3)(0,5)(4,3)(3,4)(5,5)(5,2)(1,7)(3,2)(2,2)"
Returns: { "00001M211", "0122212M1", "02MM21111", "02M6M2000", "023MM3100", "01M33M100", "011111100", "000000000", "000000000" }
"(4,6)(4,1)(3,6)(2,8)(2,7)(2,2)(4,7)(2,3)(2,6)(3,8)"
Returns: { "000000000", "012211232", "01MM12MMM", "123213M7M", "1M1002MM2", "111001221", "000000000", "000000000", "000000000" }
"(1,5)(1,6)(1,7)(2,5)(2,7)(3,5)(3,6)(3,7)(2,8)(0,4)"
Returns: { "0001M3321", "00013MMM3", "00003M8MM", "00002MMM3", "000012321", "000000000", "000000000", "000000000", "000000000" }
"(0,0)(0,8)(8,0)(8,8)"
Returns: { "M1000001M", "110000011", "000000000", "000000000", "000000000", "000000000", "000000000", "110000011", "M1000001M" }