You are viewing a single comment's thread. Return to all comments →
C++ solution :
vector<string> bomberMan(int n, vector<string> grid) { vector<string> set1=grid, set2, set3; for (int i=0;i<grid.size();i++) for (int j=0;j<grid[0].size();j++) set1[i][j]='O'; set2=set3=set1; for (int i=0;i<grid.size();i++) for (int j=0;j<grid[0].size();j++) if (grid[i][j]=='O') { if (i>0) set2[i-1][j]='.'; if (i<grid.size()-1) set2[i+1][j]='.'; if (j>0) set2[i][j-1]='.'; if (j<grid[0].size()-1) set2[i][j+1]='.'; set2[i][j]='.'; } for (int i=0;i<grid.size();i++) for (int j=0;j<grid[0].size();j++) if (set2[i][j]=='O') { if (i>0) set3[i-1][j]='.'; if (i<set2.size()-1) set3[i+1][j]='.'; if (j>0) set3[i][j-1]='.'; if (j<set2[0].size()-1) set3[i][j+1]='.'; set3[i][j]='.'; } /*cout << "Printing grid, set1, set2 : \n"; for (int i=0;i<grid.size();i++) cout << grid[i] << endl; cout << endl << endl; for (int i=0;i<grid.size();i++) cout << set1[i] << endl; cout << endl << endl; for (int i=0;i<grid.size();i++) cout << set2[i] << endl;*/ if (n%2==0) return set1; if (n==1) return grid; if (n%4==3) return set2; return set3; }
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 →
C++ solution :