Beispiel #1
0
        public DeadEndFillerResult Fill(IMazeCarver mazeCarver)
        {
            mazeCarver.DoDeadEndWrapping(model =>
            {
                var deadEndModel = _deadEndModelWrapperFactory.MakeModel(model);
                return(deadEndModel);
            });
            mazeCarver.SetState(ModelMode.DeadEndFilled);
            var deadEndsRemaining = true;
            var carvedDirections  = new List <CarvedCellResult>();

            while (deadEndsRemaining)
            {
                var pointsAndDirections = _pointsAndDirectionsRetriever
                                          .GetDeadEnds(mazeCarver)
                                          .Where(x => !_pointsAndDirectionsRetriever.PointIsStartOrEnd(x.Point, mazeCarver.StartPoint, mazeCarver.EndPoint)).ToList();
                if (!pointsAndDirections.Any())
                {
                    deadEndsRemaining = false;
                }
                else
                {
                    foreach (var pointAndDirection in pointsAndDirections)
                    {
                        mazeCarver.JumpToPoint(pointAndDirection.Point);
                        carvedDirections.AddRange(FillInPassage(mazeCarver));
                    }
                }
            }

            mazeCarver.SetState(ModelMode.Standard);
            return(new DeadEndFillerResult
            {
                CellsFilledIn = carvedDirections,
                TotalCellsFilledIn = carvedDirections.Count
            });
        }
        public void BuildMazeUI(Transform mazeField, MazeGenerationResults results, int z, UiMode mode)
        {
            mazeField.Clear();
            var maze = results.MazeJumper;

            switch (mode)
            {
            case UiMode.ShortestPath:
                maze.JumpToPoint(maze.StartPoint);
                foreach (var direction in results.HeuristicsResults.ShortestPathResult.ShortestPathDirections)
                {
                    _lineDrawer.DrawLine(mazeField, maze.CurrentPoint, direction, z, LineColour.Yellow);
                    maze.MoveInDirection(direction);
                }
                break;

            case UiMode.DeadEndLess:
                foreach (var node in results.HeuristicsResults.ShortestPathResult.Graph.Nodes)
                {
                    var point = node.Key;
                    if (point.Z == z && !_pointsAndDirectionsRetriever.PointIsStartOrEnd(point, results.MazeJumper.StartPoint, results.MazeJumper.EndPoint))
                    {
                        BuildAndAttachCircle(mazeField, "blue", point.X, point.Y);
                    }
                    maze.JumpToPoint(point);
                    foreach (var edge in node.Value.Edges)
                    {
                        maze.JumpToPoint(node.Key);
                        foreach (var direction in edge.DirectionsToPoint)
                        {
                            _lineDrawer.DrawLine(mazeField, maze.CurrentPoint, direction, z, LineColour.Blue);
                            maze.MoveInDirection(direction);
                        }
                    }
                }
                break;

            case UiMode.Agent:
                foreach (var directionAndPoint in results.AgentResults.Movements)
                {
                    maze.JumpToPoint(directionAndPoint.MazePoint);
                    _lineDrawer.DrawLine(mazeField, maze.CurrentPoint, directionAndPoint.Direction, z, LineColour.Green);
                    maze.MoveInDirection(directionAndPoint.Direction);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            var points = _mazeHelper.GetForEachZ(maze.Size, z, x => x);

            foreach (var point in points)
            {
                maze.JumpToPoint(point);
                var directions = maze.GetFlagFromPoint();
                BuildAndAttachCell(mazeField, directions, point.X, point.Y);
            }
            if (maze.StartPoint.Z == z)
            {
                BuildAndAttachDoor(mazeField, DoorType.Entrance, maze.StartPoint.X, maze.StartPoint.Y);
            }
            if (maze.EndPoint.Z == z)
            {
                BuildAndAttachDoor(mazeField, DoorType.Exit, maze.EndPoint.X, maze.EndPoint.Y);
            }
        }
Beispiel #3
0
 private bool IsStartOrEndPointOrJunction(IMazeCarver carver, List <Direction> directions)
 {
     return(_directionsRetriever.PointIsStartOrEnd(carver.CurrentPoint, carver.StartPoint, carver.EndPoint) ||
            _directionsRetriever.IsJunction(directions));
 }