You are viewing a single comment's thread. Return to all comments →
4 possible states 1. Original grid (n = 1) 2. Full of bombs (n = 2, 4, 6...) 3. Detonate 1 time (n = 3, 7, 11...) 4. Detonate 2 times (n = 5, 9, 13...)
Python3
from typing import List def bomberMan(n, grid): # 1 2. 3 # .... xxxx .x.x # o.o. oxox .... # .o.. xoxx ...x # 4 5 6 7 # oxox .... xxxx Back to 3 # oooo o.o. oxox # ooox oo.. ooxx r, c = len(grid), len(grid[0]) if n == 1: return grid elif n % 2 == 0: return ['O' * c] * r elif n % 4 == 3: # 1st-bomb pattern return detonate(grid) else: # 2nd-bomb pattern return detonate(detonate(grid)) def detonate(grid: List[str]) -> List[str]: m, n = len(grid), len(grid[0]) g = [['O'] * n for _ in range(m)] for i in range(m): for j in range(n): if grid[i][j] == '.': continue g[i][j] = '.' for ii, jj in ((i-1, j), (i+1, j), (i, j-1), (i, j+1)): if 0 <= ii < m and 0 <= jj < n: g[ii][jj] = '.' return [''.join(row) for row in g]
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 →
4 possible states
1. Original grid (n = 1)
2. Full of bombs (n = 2, 4, 6...)
3. Detonate 1 time (n = 3, 7, 11...)
4. Detonate 2 times (n = 5, 9, 13...)
Python3