Exemple #1
0
        /// <summary>
        /// Solve one step of the maze
        /// </summary>
        /// <returns>Done</returns>
        public bool SolveStep()
        {
            if (solutionRoutine == null)
            {
                if (solution == null)
                {
                    solution = new MazeSolver.Solution(this);
                }

                solutionRoutine = MazeSolver.SolveStep(solution);
            }

            solutionRoutine.MoveNext();

            bool done = false;

            if (solutionRoutine.Current != null)
            {
                done = (bool)solutionRoutine.Current;
            }

            if (done)
            {
                solutionRoutine = null;
            }

            return(done);
        }
Exemple #2
0
        /// <summary>
        /// Renders a maze
        /// </summary>
        /// <param name="maze">Maze to render</param>
        /// <param name="screenSize">Size of screen</param>
        /// <param name="visited">Visited tiles</param>
        /// <param name="solution">Solution</param>
        public void RenderMaze(Maze maze, Vector2i screenSize, MazeSolver.Solution solution = null)
        {
            Vector2 tileSize = new Vector2(screenSize.X / maze.size.X, screenSize.Y / maze.size.X);

            CreateVertices(maze, tileSize, solution);
            UpdateVAO();
            DrawVAO();
        }
Exemple #3
0
        /// <summary>
        /// Create vertices and fills vertex array for this maze
        /// </summary>
        /// <param name="maze">Maze to create vertices for</param>
        /// <param name="tileSize">Size of tiles</param>
        /// <param name="visited">Visited tiles</param>
        /// <param name="solution">Solution</param>
        private void CreateVertices(Maze maze, Vector2 tileSize, MazeSolver.Solution solution = null)
        {
            vertexCount = 0;

            // Iterate over map
            for (int i = 0; i < maze.size.X * maze.size.Y; i++)
            {
                Vector2i tilePosition = new Vector2i(
                    i % maze.size.X,
                    (int)Math.Floor((double)(i / maze.size.Y))
                    );

                Vector2 drawPosition = new Vector2(
                    tilePosition.X * tileSize.X,
                    tilePosition.Y * tileSize.Y
                    );

                // Select color based on what tile this is
                Color4 color;
                if (solution != null && solution.path.Contains(tilePosition))
                {
                    color = solutionColor;
                }
                else if (maze.startPosition == tilePosition)
                {
                    color = startColor;
                }
                else if (maze.endPosition == tilePosition)
                {
                    color = endColor;
                }
                else if (solution != null && solution.visited.Contains(tilePosition))
                {
                    color = visitedColor;
                }
                else if (maze.GetTileSolid(tilePosition))
                {
                    color = solidColor;
                }
                else
                {
                    color = emptyColor;
                }

                // Add tile
                AddTile(drawPosition, tileSize, color);
            }
        }
Exemple #4
0
 /// <summary>
 /// Solve the maze
 /// </summary>
 public void Solve()
 {
     solution = new MazeSolver.Solution(this);
     MazeSolver.Solve(solution);
 }
Exemple #5
0
 /// <summary>
 /// Clear the current solution
 /// </summary>
 public void ClearSolution()
 {
     solution = null;
 }