You are viewing a single comment's thread. Return to all comments →
def bomberMan(n: Int, grid: Array[String]): Array[String] = { val row = grid.size val col = grid(0).size if ( n == 1 ) return grid if ( (n & 1) == 0 ) { (0 until row).foreach{i=>(0 until col).foreach{j=>{ grid(i) = grid(i).replaceAll(".","O")}}} return grid } var g = grid.map{_.toCharArray} (0 until row).foreach{i=>(0 until col).foreach{j=>{ if (g(i)(j)=='.') g(i)(j) = 'x' }}} @inline def deton(p:Int,q:Int) : Unit = { g(p)(q) = '.' List((0,1),(0,-1),(-1,0),(1,0)) .map { case (x,y)=>(p+x,q+y)} .filter { case (a,b)=> a>=0 && a<row && b<col && b>=0} .foreach { case (a,b) => if (g(a)(b)=='x') g(a)(b) = '.' else if (g(a)(b)=='0') deton(a,b)} } (0 until row).foreach{i=>(0 until col).foreach{j=>{ if (g(i)(j)=='O') deton(i,j) }}} (0 until row).foreach{i=>(0 until col).foreach{j=>{ if (g(i)(j)=='x') g(i)(j)='O' }}} val ans = g.map{_.mkString} if ( ( n & 3 ) == 3 ) ans else bomberMan( n - ( n % 4 ) - 1, ans) } }
Seems like cookies are disabled on this browser, please enable them to open this website
The Bomberman Game
You are viewing a single comment's thread. Return to all comments →