We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I found the other python solutions here a little hard to understand. Hopefully this will be helpful to anyone who's stuck!
defbomberMan(n,grid):ifn==1:returngrid# The grid is totally full on every other turnifn%2==0:return["O"*len(grid[0])for_inrange(len(grid))]countdown_grid=[]forrowingrid:countdown_row=[2ifcell=="O"else-1forcellinrow]countdown_grid.append(countdown_row)planting_this_turn=Truenum_iterations=((n-2)%4)+1foriinrange(num_iterations):# plantingifplanting_this_turn:new_countdown_grid=[]forrowincountdown_grid:# 4 because we will decrement the counter this turnnew_countdown_row=[4ifcell==-1elsecellforcellinrow]new_countdown_grid.append(new_countdown_row)countdown_grid=new_countdown_grid# countdownbombs_to_detonate=[]forrowinrange(len(countdown_grid)):forcolinrange(len(countdown_grid[0])):countdown_grid[row][col]-=1ifcountdown_grid[row][col]==0:bombs_to_detonate.append((row,col))# explosionforbombinbombs_to_detonate:row,col=bombcountdown_grid[row][col]=-1if0<col:# leftcountdown_grid[row][col-1]=-1if0<row:# topcountdown_grid[row-1][col]=-1ifcol<len(countdown_grid[row])-1:# rightcountdown_grid[row][col+1]=-1ifrow<len(countdown_grid)-1:# bottomcountdown_grid[row+1][col]=-1planting_this_turn=notplanting_this_turnfinal_grid=[]forrowincountdown_grid:str_array=["."ifcell==-1else"O"forcellinrow]s="".join(str_array)final_grid.append(s)returnfinal_grid
Cookie support is required to access HackerRank
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 →
I found the other python solutions here a little hard to understand. Hopefully this will be helpful to anyone who's stuck!