示例#1
0
        public void DEC_VisitTest_10_64()
        {
            Maze maze = new Maze("BPQG.WLVB.UWPM");

            maze.CreateMaze();                                      // 14 x 10 - 2,0 .. 11,7

            DeadEndChecker target = new DeadEndChecker(maze);

            List <MazeSquare> deadSquares;

            MazeSquare sq = maze.StartSquare;                            // 2,0

            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 3,0
            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 4,0
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 4,1
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 4,2
            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 5,2
            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 6,2
            deadSquares = Move(target, ref sq, WallPosition.WP_N, 0);    // 6,1
            deadSquares = Move(target, ref sq, WallPosition.WP_W, 0);    // 5,1
            deadSquares = Move(target, ref sq, WallPosition.WP_N, 0);    // 5,0
            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 6,0
            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 7,0
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 7,1
            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 8,1
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 8,2
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 8,3
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 8,4
            deadSquares = Move(target, ref sq, WallPosition.WP_W, 0);    // 7,4
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 7,5
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 7,6
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 7,7
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 7,8
            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 8,8
            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 9,8
            deadSquares = Move(target, ref sq, WallPosition.WP_N, 0);    // 9,7
            deadSquares = Move(target, ref sq, WallPosition.WP_E, 0);    // 10,7
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 10,8
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 64);   // 10,9
        }
        private Position GetPositionForLeftDirectionMirror(MazeSquare currentMazeSquare, ref LazerDirection lazerDirection)
        {
            if (currentMazeSquare.Mirror.ReflectiveSide == MirrorReflectiveSide.Left && (lazerDirection == LazerDirection.South || lazerDirection == LazerDirection.West))
                return GetNextPosition(currentMazeSquare, lazerDirection);

            if (currentMazeSquare.Mirror.ReflectiveSide == MirrorReflectiveSide.Right && (lazerDirection == LazerDirection.North || lazerDirection == LazerDirection.East))
                return GetNextPosition(currentMazeSquare, lazerDirection);

            if (currentMazeSquare.Mirror.ReflectiveSide == MirrorReflectiveSide.Right && (lazerDirection == LazerDirection.South || lazerDirection == LazerDirection.West))
            {
                _lazerService.ChangeLazerDirection(currentMazeSquare.Mirror.Direction, ref lazerDirection);
                return GetNextPosition(currentMazeSquare, lazerDirection);
            }

            if (currentMazeSquare.Mirror.ReflectiveSide == MirrorReflectiveSide.Left && (lazerDirection == LazerDirection.North || lazerDirection == LazerDirection.East))
            {
                _lazerService.ChangeLazerDirection(currentMazeSquare.Mirror.Direction, ref lazerDirection);
                return GetNextPosition(currentMazeSquare, lazerDirection);
            }

            return null;
        }
示例#3
0
        public void DEC_VisitTest_03_20()
        {
            Maze maze = new Maze("BPQG.WLVB.UWPM");

            maze.CreateMaze();                                      // 14 x 10 - 2,0 .. 11,7

            DeadEndChecker target = new DeadEndChecker(maze);

            List <MazeSquare> deadSquares;

            MazeSquare sq = maze.StartSquare;                            // 2,0

            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 2,1
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 2,2
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 2,3
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 2,4
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 2,5
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 2,6
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 2,7
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 0);    // 2,8
            deadSquares = Move(target, ref sq, WallPosition.WP_S, 20);   // 2,9
        }
        private Position GetNextPosition(MazeSquare currentMazeSquare, LazerDirection lazerDirection)
        {
            var newPosY = currentMazeSquare.Position.Y + 1;

            var newNegY = currentMazeSquare.Position.Y - 1;

            var newPosX = currentMazeSquare.Position.X + 1;

            var newNegX = currentMazeSquare.Position.X - 1;

            if (lazerDirection == LazerDirection.North)
                return new Position { X = currentMazeSquare.Position.X, Y = newPosY };

            if (lazerDirection == LazerDirection.South)
                return new Position { X = currentMazeSquare.Position.X, Y = newNegY };

            if (lazerDirection == LazerDirection.East)
                return new Position { X = newPosX, Y = currentMazeSquare.Position.Y };

            if (lazerDirection == LazerDirection.West)
                return new Position { X = newNegX, Y = currentMazeSquare.Position.Y };

            return null;
        }
示例#5
0
        public void SB_OpenWallsTest_01()
        {
            string testObject = "SWA.Ariadne.Logic.SolverBase.OpenWalls";

            MazeSquare sq = new MazeSquare(0, 0);

            for (WallPosition wp = WallPosition.WP_MIN; wp <= WallPosition.WP_MAX; wp++)
            {
                sq[wp] = WallState.WS_CLOSED;
            }

            Maze maze = new Maze(0, 0);

            maze.CreateMaze();
            IMazeSolver target = SolverFactory.CreateDefaultSolver(maze, null);
            SWA_Ariadne_Logic_SolverBaseAccessor accessor = new SWA_Ariadne_Logic_SolverBaseAccessor(target);

            bool notVisitedOnly = false;
            List <WallPosition> actual;

            actual = accessor.OpenWalls(sq, notVisitedOnly);

            Assert.AreEqual(0, actual.Count, testObject + " did not return the expected value.");
        }
示例#6
0
        public LazerDirection GetInitialLazerDirection(MazeSquare mazeSquare, string orientation)
        {
            if (mazeSquare.HasNorthPerimeterDoor && orientation == "V")
            {
                return(LazerDirection.South);
            }

            if (mazeSquare.HasSouthPerimeterDoor && orientation == "V")
            {
                return(LazerDirection.North);
            }

            if (mazeSquare.HasWestPerimeterDoor && orientation == "H")
            {
                return(LazerDirection.East);
            }

            if (mazeSquare.HasEastPerimeterDoor && orientation == "H")
            {
                return(LazerDirection.West);
            }

            return(LazerDirection.Unspecified);
        }
示例#7
0
        /// <summary>
        /// Advance a single step.
        /// The traveled steps are not rendered until FinishPath() is called.
        /// Returns the number of steps actually executed.
        /// </summary>
        /// <returns></returns>
        public int DoStep()
        {
            int result = 0;

            if (RunParallelSolvers)
            {
                // All controllers run in parallel.
                // Forward the message to the embedded controllers.
                foreach (EmbeddedSolverController item in embeddedControllers)
                {
                    if (item.IsActive)
                    {
                        result += item.DoStep();
                    }
                }
            }
            else
            {
                SolverController ctrl = ChooseDueController();

                if (ctrl != this)
                {
                    return(ctrl.DoStep());
                }
            }

            if (this.Maze.IsSolved)
            {
                return(result);
            }

            MazeSquare sq1, sq2;
            bool       forward;

            solver.Step(out sq1, out sq2, out forward);
            mazePainter.DrawStep(sq1, sq2, forward);
            ++result;

            // Increment the step counter.
            ++countSteps;

            // Increment forward and backward counters.
            if (forward)
            {
                ++countForward;
                if (visitedProgressBar != null)
                {
                    visitedProgressBar.PerformStep(); // next visited square
                }

                // Let all embedded controllers know how far we have advanced.
                foreach (EmbeddedSolverController ctrl in embeddedControllers)
                {
                    ctrl.HostStep(sq2);
                }
            }
            else
            {
                ++countBackward;
            }

            currentBackwardSquare = (forward ? null : sq2);

            if (this.Maze.IsSolved)
            {
                FinishPath();
                mazePainter.DrawSolvedPath(solutionPath);
                currentBackwardSquare = null;

                if (this.Maze.MazeId != MazeSquare.PrimaryMazeId)
                {
                    mazePainter.DrawRemainingSquares();
                }

#if DEBUG
                if (RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_LOG_SOLVER_STATISTICS))
                {
                    LogSolverStatistics();
                }
#endif
            }

            // Draw the background image inside the reserved areas.
            // If the background image was covered by a ContourImage, that border will be drawn smoothly instead of jagged.
            if (this.Maze.MazeId == MazeSquare.PrimaryMazeId && this.Maze.IsFinished)
            {
                mazePainter.DrawRemainingBackgroundSquares(MazeSquare.ReservedMazeId);
            }

            return(result);
        }
 private bool MazeSquareHasMirror(MazeSquare square)
 {
     return square.Mirror != null;
 }
示例#9
0
    public static void SurveyOutlet(MazeSquare rootSquare, int adjacencyIndex, MazeSquare[,,] grid, out MazeSquare outletSquare)
    {
        rootSquare.adjacents[adjacencyIndex] = new MazeSquare(
            rootSquare.xCoord + directions[adjacencyIndex][0],
            rootSquare.yCoord + directions[adjacencyIndex][1],
            rootSquare.zCoord + directions[adjacencyIndex][2]
            );

        outletSquare          = rootSquare.adjacents[adjacencyIndex];
        outletSquare.isOutlet = true;

        if (outletSquare.xCoord >= 0 && outletSquare.xCoord < grid.GetLength(0) &&
            outletSquare.yCoord >= 0 && outletSquare.yCoord < grid.GetLength(1) &&
            outletSquare.zCoord >= 0 && outletSquare.zCoord < grid.GetLength(2))
        {
            grid[outletSquare.xCoord, outletSquare.yCoord, outletSquare.zCoord] = outletSquare;
            Survey(outletSquare.xCoord, outletSquare.yCoord, outletSquare.zCoord, grid);

            //Fill open slot of any square adjacent to this new outlet
            for (int i = 0; i < outletSquare.adjacents.Length; i++)
            {
                if (outletSquare.adjacents[i] != null)
                {
                    outletSquare.adjacents[i].adjacents[adjDirectionFlips[i]] = outletSquare;
                }
            }
        }
    }
示例#10
0
 /// <summary>
 /// Select one of the open walls leading away from the given square.
 /// </summary>
 /// <param name="sq1"></param>
 /// <param name="openWalls"></param>
 /// <returns></returns>
 protected override WallPosition SelectDirection(MazeSquare sq1, List <WallPosition> openWalls)
 {
     return(openWalls[0]);
 }
示例#11
0
 /// <summary>
 /// Travel from one visited square to a neighbor square (through an open wall).
 /// Implementation of Step().
 /// </summary>
 /// <param name="sq1">first (previously visited) square</param>
 /// <param name="sq2">next (neighbor) square</param>
 /// <param name="forward">true if the neighbor square was not visited previously</param>
 protected abstract void StepI(out MazeSquare sq1, out MazeSquare sq2, out bool forward);
示例#12
0
    public static void SetOutlet(bool useColumns, LevelPrefabs prefabs, GameObject outlet, out MazeSquare outletSq, MazeSquare[,,] squares)
    {
        List <MazeSquare> vacancyList = new List <MazeSquare>();

        vacancyList = FillVacancyList(vacancyList, squares);

        int        outletIndex = Random.Range(0, vacancyList.Count);
        MazeSquare square      = vacancyList[outletIndex];
        MazeSquare tempSq;

        //Identify and store the root square's open adjacent squares
        List <int>        indices       = new List <int>();
        List <MazeSquare> openAdjacents = new List <MazeSquare>();

        for (int i = 0; i < CORNERS; i++)
        {
            if (square.adjacents[i] == null)
            {
                openAdjacents.Add(square.adjacents[i]);
                indices.Add(i);
            }
        }

        int rand = Random.Range(0, openAdjacents.Count);

        MazeSurveyLogic.SurveyOutlet(square, indices[rand], squares, out tempSq);
        outletSq = tempSq;

        //Replace wall with outlet
        Transform wall = square.layout.transform.GetChild(indices[rand]);

        Object.Destroy(wall.GetChild(0).gameObject);
        outlet = Object.Instantiate(outlet, wall);
        ZeroOut(outlet);
        outletSq.layout = outlet;

        if (vacancyList.Count > 1)
        {
            vacancyList.RemoveAt(outletIndex);
        }
    }
示例#13
0
 /// <summary>
 /// Select one of the open walls leading away from the given square.
 /// </summary>
 /// <param name="sq1"></param>
 /// <param name="openWalls"></param>
 /// <returns></returns>
 protected override WallPosition SelectDirection(MazeSquare sq1, List <WallPosition> openWalls)
 {
     return(openWalls[random.Next(openWalls.Count)]);
 }
示例#14
0
    static void LinkByClusters(List <List <List <MazeSquare[]> > > gridClusters, MazeSquare[,,] squares)
    {
        int length = squares.GetLength(0);
        int height = squares.GetLength(2);

        for (int z = 0; z < height; z++)
        {
            for (int i = 1; i < length; i++)
            {
                //Iterate through clusters
                for (int j = 0; j < gridClusters[z][i].Count; j++)
                {
                    int connections = 0;

                    for (int k = 0; k < gridClusters[z][i][j].Length; k++)
                    {
                        MazeSquare current = gridClusters[z][i][j][k];

                        if (squares[i - 1, current.yCoord, current.zCoord] != null)
                        {
                            connections++;
                        }
                    }

                    if (connections == 0)
                    {
                        //Scout out to the first row to find where this cluster can connect
                        bool hit = false;

                        for (int k = 0; k < gridClusters[z][i][j].Length; k++)
                        {
                            MazeSquare current = gridClusters[z][i][j][k];

                            for (int l = i - 1; l >= 0; l--)
                            {
                                if (squares[l, current.yCoord, current.zCoord] != null)
                                {
                                    hit = true;
                                    for (int m = i - 1; m > l; m--)
                                    {
                                        squares[m, current.yCoord, current.zCoord] = new MazeSquare(m, current.yCoord, current.zCoord);
                                    }

                                    break;
                                }
                            }

                            if (hit == true)
                            {
                                break;
                            }
                        }

                        //If there's nowhere it can connect, draw a line down, then to the first row, then to the origin
                        if (hit == false)
                        {
                            MazeSquare sq = gridClusters[z][i][j][0];

                            for (int k = i - 1; k >= 0; k--)
                            {
                                squares[k, sq.yCoord, sq.zCoord] = new MazeSquare(k, sq.yCoord, sq.zCoord);
                            }

                            for (int k = sq.yCoord; k >= gridClusters[0][0][0].Length; k--)
                            {
                                if (squares[0, k, 0] == null)
                                {
                                    squares[0, k, 0] = new MazeSquare(0, k, 0);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
示例#15
0
    public static void WriteClusters(float gapFrequency, out List <List <List <MazeSquare[]> > > gridClusters, MazeSquare[,,] squares)
    {
        gridClusters = new List <List <List <MazeSquare[]> > >();
        int length = squares.GetLength(0);
        int width  = squares.GetLength(1);
        int height = squares.GetLength(2);

        for (int z = 0; z < height; z++)
        {
            gridClusters.Add(new List <List <MazeSquare[]> >());

            for (int i = 0; i < length; i++)
            {
                List <MazeSquare[]> rowClusters = new List <MazeSquare[]>();
                int clusterSize = 0;

                for (int j = 0; j < width; j++)
                {
                    MazeSquare[] cluster;

                    //Only 1 cluster for the origin
                    if (i == 0 && j == 0)
                    {
                        squares[i, j, z] = new MazeSquare(i, j, z);
                        clusterSize++;
                        continue;
                    }

                    //Store clusters
                    float rand = Random.Range(0, 1f);
                    if (rand < gapFrequency)
                    {
                        if (clusterSize > 0)
                        {
                            //Cluster excluding current (null) square
                            cluster = SetCluster(clusterSize, i, j, z, squares);
                            rowClusters.Add(cluster);
                            clusterSize = 0;
                        }

                        if (i == 0)
                        {
                            break;
                        }
                        continue;
                    }

                    squares[i, j, z] = new MazeSquare(i, j, z);

                    clusterSize++;
                    if (j == width - 1)
                    {
                        //Cluster including current (!null) square
                        cluster = SetCluster(clusterSize, i, j + 1, z, squares);
                        rowClusters.Add(cluster);
                    }
                }

                gridClusters[z].Add(rowClusters);
            }
        }

        LinkByClusters(gridClusters, squares);
    }
示例#16
0
 /// <summary>
 /// Select one of the open walls leading away from the given square.
 /// </summary>
 /// <param name="sq1"></param>
 /// <param name="openWalls"></param>
 /// <returns></returns>
 protected abstract WallPosition SelectDirection(MazeSquare sq1, List <WallPosition> openWalls);