private bool CanBeShortCut(bool[,] maze, int x, int y) { if (MazeHelper.IsRoad(maze, x, y)) { return(false); } bool isLeftRoad = MazeHelper.IsRoad(maze, x - 1, y); bool isRightRoad = MazeHelper.IsRoad(maze, x + 1, y); if (isLeftRoad && isRightRoad) { return(true); } bool isTopRoad = MazeHelper.IsRoad(maze, x, y + 1); bool isBottomRoad = MazeHelper.IsRoad(maze, x, y - 1); if (isTopRoad && isBottomRoad) { return(true); } return(false); }
private void Connect(bool[,] maze, int x, int y) { int[,] directions = new int[, ] { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; ShuffleUtility.Shuffle(directions); for (int i = 0; i < directions.GetLength(0); i++) { // Нужно направление умножать на 2 // чтоб оставлять стенку размером в 1 ячейку int neighborX = x + directions[i, 0] * 2; int neighborY = y + directions[i, 1] * 2; if (MazeHelper.IsRoad(maze, neighborX, neighborY)) { int connectorX = x + directions[i, 0]; int connectorY = y + directions[i, 1]; maze[connectorY, connectorX] = true; return; } } }
private void AddVisitPoints(HashSet <Tuple <int, int> > visited, LinkedList <Node> shouldVisit, int x, int y, Node parent) { var directions = MazeHelper.directions; for (int i = 0; i < directions.GetLength(0); i++) { int newX = x + directions[i, 0]; int newY = y + directions[i, 1]; bool isRoad = MazeHelper.IsRoad(_map, newX, newY); bool wasVisited = visited.Contains(new Tuple <int, int>(newX, newY)); if (isRoad && wasVisited == false) { shouldVisit.AddLast(new Node(newX, newY, parent)); } } }
private void AddVisitPoints(bool[,] maze, HashSet <Tuple <int, int> > points, int x, int y) { if (MazeHelper.IsPointInMaze(maze, x - 2, y) && MazeHelper.IsRoad(maze, x - 2, y) == false) { points.Add(new Tuple <int, int>(x - 2, y)); } if (MazeHelper.IsPointInMaze(maze, x + 2, y) && MazeHelper.IsRoad(maze, x + 2, y) == false) { points.Add(new Tuple <int, int>(x + 2, y)); } if (MazeHelper.IsPointInMaze(maze, x, y - 2) && MazeHelper.IsRoad(maze, x, y - 2) == false) { points.Add(new Tuple <int, int>(x, y - 2)); } if (MazeHelper.IsPointInMaze(maze, x, y + 2) && MazeHelper.IsRoad(maze, x, y + 2) == false) { points.Add(new Tuple <int, int>(x, y + 2)); } }