Ejemplo n.º 1
0
        private Bitmap RenderMaze()
        {
            Bitmap      mazeImage = null;
            IMazeDrawer drawer    = MazeDrawersFactory.Instance.Create(drawingAlgo);

            drawer.SetDrawingSettings(drawingSettings);
            drawer = new MazeDrawerRotateDecorator(drawer, mazeRotation);

            try
            {
                if (maze != null)
                {
                    if (showMazeClustersCheckbox.Checked)
                    {
                        mazeImage = drawer.Draw(maze, clusters);
                    }
                    else
                    {
                        mazeImage = drawer.Draw(maze);
                    }
                }
            }
            catch (MazeException ex)
            {
                DebugConsole.Instance.Error(
                    string.Format("Возникло исключение: {0}", ex.ToString()));
            }
            return(mazeImage);
        }
Ejemplo n.º 2
0
        public void SF_CreateDefaultSolverTest_01()
        {
            string testObject = "SWA.Ariadne.Logic.SolverFactory.CreateDefaultSolver";

            Maze        maze       = NewMaze();
            IMazeDrawer mazeDrawer = null;
            IMazeSolver actual     = SolverFactory.CreateDefaultSolver(maze, mazeDrawer);

            Assert.IsInstanceOfType(actual, SolverFactory.DefaultStrategy, testObject + " did not return an instance of the default strategy.");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="maze"></param>
        /// <param name="mazeDrawer"></param>
        public ThickestBranchFlooder(Maze maze, IMazeDrawer mazeDrawer)
            : base(maze, mazeDrawer)
        {
            this.branchExtension = new BranchExtension[maze.XSize, maze.YSize];

            MazeSquare sq0 = maze.StartSquare;

            branchExtension[sq0.XPos, sq0.YPos].length    = 0;
            branchExtension[sq0.XPos, sq0.YPos].thickness = 0;
        }
Ejemplo n.º 4
0
        public void SF_CreateSolverTest_01()
        {
            string testObject = "SWA.Ariadne.Logic.SolverFactory.CreateSolver";

            Maze        maze       = NewMaze();
            IMazeDrawer mazeDrawer = null;
            IMazeSolver actual     = SolverFactory.CreateSolver(null, maze, mazeDrawer);

            Assert.IsInstanceOfType(actual, typeof(IMazeSolver), testObject + " did not return an instanze of IMazeSolver");
        }
Ejemplo n.º 5
0
        public void SF_CreateSolverTest_type_01()
        {
            string testObject = "SWA.Ariadne.Logic.SolverFactory.CreateSolver(type)";

            foreach (Type solverType in SolverFactory.SolverTypes)
            {
                Maze        maze       = NewMaze();
                IMazeDrawer mazeDrawer = null;
                IMazeSolver actual     = SWA_Ariadne_Logic_SolverFactoryAccessor.CreateSolver(solverType, maze, mazeDrawer);

                Assert.IsInstanceOfType(actual, typeof(IMazeSolver), testObject + " did not return an instanze of IMazeSolver");
                Assert.IsInstanceOfType(actual, solverType, testObject + " did not return the given type");
            }
        }
Ejemplo n.º 6
0
        public void SB_SolveTest_01()
        {
            string testObject = "SWA.Ariadne.Logic.SolverBase.Solve";

            foreach (Type solverType in SolverFactory.SolverTypes)
            {
                Maze        maze       = SolverFactoryTest.NewMaze();
                IMazeDrawer mazeDrawer = null;
                IMazeSolver target     = SWA_Ariadne_Logic_SolverFactoryAccessor.CreateSolver(solverType, maze, mazeDrawer);
                target.Solve();

                Assert.IsTrue(maze.IsSolved, testObject + ": " + target.GetType().Name + " did not solve the maze.");
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns a new MazeSolver of the given Type.
        /// </summary>
        /// <param name="solverType"></param>
        /// <param name="maze"></param>
        /// <returns></returns>
        private static IMazeSolver CreateSolver(Type solverType, Maze maze, IMazeDrawer mazeDrawer)
        {
            IMazeSolver result = (IMazeSolver)solverType.GetConstructor(
                new Type[2] {
                typeof(Maze), typeof(IMazeDrawer)
            }).Invoke(
                new object[2] {
                maze, mazeDrawer
            }
                );

            result.Reset();

            return(result);
        }
Ejemplo n.º 8
0
        public MasterSolver(Maze maze, IMazeDrawer mazeDrawer)
            : base(maze, mazeDrawer)
        {
            // Instead of operating on the original maze, we need to make a copy first.
            Maze helperMaze = maze.Clone();

            helperMaze.Reset();

            // Use another MazeSolver to find the path from start to end.
            RoundRobinFlooder helper = new RoundRobinFlooder(helperMaze, null);

            helper.Reset();
            helper.Solve();

            this.path = helper.PathFromStartSquare(maze.EndSquare);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns a new MazeSolver.
        /// If the strategyName is valid, that type is created; otherwise a random type is returned.
        /// </summary>
        public static IMazeSolver CreateSolver(string strategyName, Maze maze, IMazeDrawer mazeDrawer)
        {
            IMazeSolver result;
            bool        isEfficient  = false;
            bool        useHeuristic = false;

            if (strategyName != null)
            {
                if (strategyName.StartsWith(EfficientPrefix, StringComparison.Ordinal))
                {
                    strategyName = strategyName.Substring(EfficientPrefix.Length);
                    isEfficient  = true;
                }
                if (strategyName.StartsWith(HeuristicPrefix, StringComparison.Ordinal))
                {
                    strategyName = strategyName.Substring(HeuristicPrefix.Length);
                    useHeuristic = true;
                }
            }

            Type strategy = SolverType(strategyName);

            if (strategy != null)
            {
                // If strategyName is a valid solver type name:
                result = CreateSolver(strategy, maze, mazeDrawer);
                if (isEfficient)
                {
                    result.MakeEfficient();
                }
                if (useHeuristic)
                {
                    result.UseHeuristic();
                }
            }
            else
            {
                // Otherwise (strategy name is "any"):
                result = CreateSolver(maze, mazeDrawer);
            }

            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns a new MazeSolver.
        /// A (reasonably) intelligent strategy is chosen randomly.
        /// </summary>
        /// <param name="maze"></param>
        /// <returns></returns>
        private static IMazeSolver CreateSolver(Maze maze, IMazeDrawer mazeDrawer)
        {
            Random r = SWA.Utilities.RandomFactory.CreateRandom();

            while (true)
            {
                Type t = solverTypes[r.Next(solverTypes.Length)];
                bool shouldBeEfficient = (r.Next(2) == 0);
                shouldBeEfficient &= RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_EFFICIENT_SOLVERS);
                bool shouldUseHeuristic = (r.Next(2) == 0);
                // Note: There is currently no equivaelnt OPT_HEURISTIC_SOLVERS option.

                if (t == typeof(RandomWalker))
                {
                    // too dumb
                    continue;
                }

                if (t == typeof(MasterSolver))
                {
                    // too smart
                    continue;
                }

                IMazeSolver result = CreateSolver(t, maze, mazeDrawer);

                if (shouldBeEfficient && HasEfficientVariant(t))
                {
                    result.MakeEfficient();
                }
                if (shouldUseHeuristic && HasHeuristicVariant(t))
                {
                    result.UseHeuristic();
                }

                return(result);
            }
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public DirectionGuidedFlooderBase(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
 }
 public MazeDrawerRotateDecorator(IMazeDrawer drawer, MazeRotateEnum rotate) :
     base(drawer)
 {
     rotateMaze = rotate;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public RoundRobinFlooder(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public BacktrackerBase(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public DistanceGuidedBacktrackerBase(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public CornerFlooder(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
     // Invert the parent strategy: Maximize distance from the reference square.
     this.distanceSign = -1;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public DistanceGuidedFlooderBase(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public CenterFlooder(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
     this.referenceSquare = maze.GetCenterSquare();
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Returns a new MazeSolver.
 /// The default strategy.
 /// </summary>
 /// <param name="maze"></param>
 /// <returns></returns>
 public static IMazeSolver CreateDefaultSolver(Maze maze, IMazeDrawer mazeDrawer)
 {
     return(CreateSolver(DefaultStrategy, maze, mazeDrawer));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public RightHandWalker(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public DeterministicWalker(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 protected SolverBase(Maze maze, IMazeDrawer mazeDrawer)
 {
     this.maze       = maze;
     this.mazeDrawer = mazeDrawer;
     this.random     = SWA.Utilities.RandomFactory.CreateRandom();
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public FlooderBase(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
     this.mazeExtension = new MazeSquareExtension[maze.XSize, maze.YSize];
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public ProximityBacktracker(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
     this.referenceSquare = maze.EndSquare;
 }
Ejemplo n.º 25
0
 public MazeDrawerDecorator(IMazeDrawer drawer)
 {
     mazeDrawer = drawer;
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public SpreadingFlooder(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public RandomBacktracker(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public OpposedBacktracker(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
     this.referenceSquare = maze.GetOpposedSquare(maze.StartSquare);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public ThinnestBranchFlooder(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
     this.thicknessSign = -1;
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="maze"></param>
 /// <param name="mazeDrawer"></param>
 public ForwardFlooder(Maze maze, IMazeDrawer mazeDrawer)
     : base(maze, mazeDrawer)
 {
     this.referenceSquare = maze.EndSquare;
 }
Ejemplo n.º 31
0
 public void Draw(IMazeDrawer drawer)
 {
     if (drawer == null)
         throw new ArgumentNullException("drawer");
     drawer.StartLayout(Width, Height);
     for (var w = 0; w < Width; w++)
         for (var h = 0; h <= Height; h++)
             if (HWalls[w, h])
                 drawer.DrawWall(new Position(w, h), new Position(w + 1, h));
     for (var w = 0; w <= Width; w++)
         for (var h = 0; h < Height; h++)
             if (VWalls[w, h])
                 drawer.DrawWall(new Position(w, h), new Position(w, h + 1));
     drawer.LayoutDone();
 }