that_one_nigga_you_k

com loops em DFS

Jun 12th, 2024
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. // Output the maze before tearing down walls
  2.     cout << "Maze before tearing down walls:" << endl;
  3.     for (int i = 0; i < largura; i++) {
  4.         for (int j = 0; j < comprimento; j++) {
  5.             cout << layout[i][j] << " ";
  6.         }
  7.         cout << endl;
  8.     }
  9.  
  10.     // Tear down internal walls to create loops
  11.     vector<pair<int, int>> paredes_p_derrubar;
  12.     for (int i = 1; i < largura - 1; i++) {
  13.         for (int j = 1; j < comprimento - 1; j++) {
  14.             if (layout[i][j] == '@' && (
  15.                 (layout[i - 1][j] == ' ' && layout[i + 1][j] == ' ') ||
  16.                 (layout[i][j - 1] == ' ' && layout[i][j + 1] == ' '))) {
  17.                 paredes_p_derrubar.push_back({i, j});
  18.             }
  19.         }
  20.     }
  21.  
  22.     uniform_real_distribution<> dis(0.0, 0.7);
  23.     double porcentagem_aleat = dis(g);
  24.     int paredes_derrubar = floor(porcentagem_aleat * paredes_p_derrubar.size());
  25.  
  26.     shuffle(paredes_p_derrubar.begin(), paredes_p_derrubar.end(), g);
  27.  
  28.     for (int i = 0; i < paredes_derrubar; i++) {
  29.         auto [x_d, y_d] = paredes_p_derrubar[i];
  30.         layout[x_d][y_d] = ' ';
  31.     }
  32.  
  33.     // Output the maze after tearing down walls
  34.     cout << "Maze after tearing down walls:" << endl;
  35.     for (int i = 0; i < largura; i++) {
  36.         for (int j = 0; j < comprimento; j++) {
  37.             cout << layout[i][j] << " ";
  38.         }
  39.         cout << endl;
  40.     }
  41.  
Add Comment
Please, Sign In to add comment