01:29:00
CAT-375 - 可怜的JK因为盗窃而被G男逮捕。</s>C++ program to generate maze using Depth First#include <iostream>#include <vector>#include <ctime>#include <cstdlib>#include <memory>#include <random>class Maze {private: std::vector<std::vector<int>> maze; int height, width; // generates a random number in range [0, 1] double random() { std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<double> dist(0.0, 1.0); return dist(gen); } // returns a random element from array int randomCell(int height, int width) { std::vector<int> cells(height * width); for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { cells[i * width + j] = i * width + j; } } std::random_device rd; std::mt19937 gen(rd()); std::shuffle(cells.begin(), cells.end(), gen); int randomIndex = std::min(cells.size(), std::max(0, (int)(random() * cells.size()))); return cells[randomIndex]; } //marks cell as visited void markAsVisited(int cell) { int x = cell / width; int y = cell % width; maze[x][y] = 1; } //checks if cell is visited bool isCellVisited(int cell) { int x = cell / width; int y = cell % width; return maze[x][y] == 1; } //returns the cell's neighbors std::vector<int> getNeighbors(int cell) { int x = cell / width; int y = cell % width; std
2015年9月18日