You are viewing a single comment's thread. Return to all comments →
Great problem. I did the following:
My JS solution is below:
if(n === 1){ return grid; } if((n-1)%4 === 0){ let grid2 = bombGrid(grid); return bombGrid(grid2); } if(n%2 === 0){ let str = ``; for(let i = 0; i < grid[0].length; i++){ str += `O`; } for(let i = 0; i < grid.length; i++){ grid[i] = str; } return grid; } return bombGrid(grid); function bombGrid(g){ let g2 = new Array (g.length); g2[0] = new Array (g[0].length); for(let i = 0; i < g.length; i++){ if(i !== g.length-1){ g2[i+1] = new Array(g[i].length); } for(let j = 0; j < g[i].length; j++){ if(g[i].charAt(j) === `O`){ g2[i][j] = `.`; if(j !== g[i].length-1){ g2[i][j+1] = `.`; } if(j !== 0){ g2[i][j-1] = `.`; } if(i !== 0){ g2[i-1][j] = `.`; } if(i !== g.length-1){ g2[i+1][j] = `.`; } } else if(g2[i][j] === undefined){ g2[i][j] = `O`; } } if(i !== 0){ g2[i-1] = g2[i-1].join(``); } if(i === g.length-1){ g2[i] = g2[i].join(``); } } return g2; }
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 →
Great problem. I did the following:
My JS solution is below: