Ejemplo n.º 1
0
        private void VerifyMazeIsValid()
        {
            // Make sure every cell can be reached
            var distanceInfo = CellDistanceSolver.GetDistancesForUnlinkedMaze(this);

            if (distanceInfo.DistanceFromStartMap.Count != AllCells.Count)
            {
                throw new InvalidOperationException("Not all cells are reachable!");
            }
        }
Ejemplo n.º 2
0
        private void SetStartingAndEndingCells()
        {
            var startingRow = _random.Next(0, RowCount);

            StartingCell = GetCell(startingRow, 0);

            var distanceInfo = CellDistanceSolver.GetPassableDistancesFromCell(StartingCell);

            FinishingCell = FindFarthestEdgeCell(distanceInfo);
        }
Ejemplo n.º 3
0
        public void LoadMaze(IMaze maze, MazeStats mazeStats)
        {
            _currentMaze          = maze;
            _currentStats         = mazeStats;
            _mazeDistanceInfo     = CellDistanceSolver.GetPassableDistancesFromCell(_currentMaze.StartingCell);
            _mazeShortestPathInfo = ShortestPathSolver.Solve(_currentMaze.FinishingCell, _mazeDistanceInfo);

            UpdateMazeRendering();
            ResetMazePositionAndScaling();
        }
Ejemplo n.º 4
0
        private void SetStartingAndFinishingCells()
        {
            // Starting and finishing cells should be on the outer ring
            var cellsInRing = _cellsInRingMap[RingCount - 1];

            StartingCell = cellsInRing[_random.Next(0, cellsInRing.Length)];

            var distanceInfo = CellDistanceSolver.GetPassableDistancesFromCell(StartingCell);

            FinishingCell = cellsInRing.Select(x => new { cell = x, distance = distanceInfo.DistanceFromStartMap[x] })
                            .OrderByDescending(x => x.distance)
                            .Select(x => x.cell)
                            .First();
        }
Ejemplo n.º 5
0
        private void SetStartAndFinishingCells()
        {
            var startingCandidates  = Enumerable.Range(0, RowCount).Select(x => GetCell(x, 0)).ToArray();             // left
            var finishingCandidates = startingCandidates
                                      .Concat(Enumerable.Range(0, RowCount).Select(x => GetCell(x, ColumnCount - 1))) // right
                                      .Concat(Enumerable.Range(0, ColumnCount).Select(x => GetCell(0, x)))            // top
                                      .Concat(Enumerable.Range(0, ColumnCount).Select(x => GetCell(RowCount - 1, x))) // bottom
                                      .ToArray();

            StartingCell = startingCandidates[_random.Next(0, startingCandidates.Length)];

            var distanceInfo = CellDistanceSolver.GetPassableDistancesFromCell(StartingCell);

            FinishingCell = finishingCandidates.Select(x => new { cell = x, distance = distanceInfo.DistanceFromStartMap[x] })
                            .OrderByDescending(x => x.distance)
                            .Select(x => x.cell)
                            .First();
        }
Ejemplo n.º 6
0
        private void SetStartingAndFinishingCell()
        {
            // Starting cell should always be a random cell in the leftmost column
            Cell[] candidates;
            var    column = 0;

            do
            {
                candidates = GetCellsInColumn(column);
                column++;
            } while (!candidates.Any());

            StartingCell = candidates[_random.Next(0, candidates.Length)];

            var distanceInfo = CellDistanceSolver.GetPassableDistancesFromCell(StartingCell);

            FinishingCell = FindFarthestEdgeCell(distanceInfo);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            const string pngFileName = "rendering.png";

            var maze                 = new TriangleMaze(20, 40, WallSetupAlgorithm.RecursiveBackTracker);
            var mazeDistanceInfo     = CellDistanceSolver.GetPassableDistancesFromCell(maze.StartingCell);
            var mazeShortestPathInfo = ShortestPathSolver.Solve(maze.FinishingCell, mazeDistanceInfo);
            var renderOptions        = new RenderOptions
            {
                ShowGradientOfDistanceFromStart = true,
                HighlightShortestPath           = true,
                //ShowAllDistances = true,
            };

            using (var image = maze.RenderWithSkia(renderOptions, mazeDistanceInfo, mazeShortestPathInfo))
                using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
                    using (var stream = File.OpenWrite(pngFileName))
                    {
                        data.SaveTo(stream);
                    }
        }