コード例 #1
0
ファイル: MazeLoader.cs プロジェクト: Tjakka5/MazeSolver
        /// <summary>
        /// Loads a predefined Maze
        /// </summary>
        /// <param name="mazeType">Type of maze to load</param>
        /// <returns>Loaded Maze</returns>
        public static void LoadMaze(Maze maze, MazeType mazeType)
        {
            int[,] mazeData;             // mazeData to read from

            // Select mazeData
            switch (mazeType)
            {
            case MazeType.Test1:
                mazeData = mapTest1;
                break;

            case MazeType.Test2:
                mazeData = mapTest2;
                break;

            case MazeType.Test3:
                mazeData = mapTest3;
                break;

            default:
                mazeData = mapDefault;
                break;
            }
            ;

            // Create maze
            Vector2i mazeSize = new Vector2i(mazeData.GetLength(0), mazeData.GetLength(1));

            maze.SetSize(mazeSize);

            // Build maze from mazeData
            for (int i = 0; i < mazeData.Length; i++)
            {
                Vector2i tilePosition = new Vector2i(
                    i % maze.size.X,
                    (int)Math.Floor((double)(i / maze.size.Y))
                    );

                int tileData = mazeData[tilePosition.Y, tilePosition.X];                 // Inverse since rows and columns are inversed when typing it as code

                switch (tileData)
                {
                case 0:
                    maze.SetTileSolid(tilePosition, false);
                    break;

                case 1:
                    maze.SetTileSolid(tilePosition, true);
                    break;

                case 2:
                    maze.startPosition = tilePosition;
                    break;

                case 3:
                    maze.endPosition = tilePosition;
                    break;
                }
            }
        }
コード例 #2
0
ファイル: Tree.cs プロジェクト: Maelidrem/Dojo
        public static List <Cell> GetTree(MazeType type)
        {
            Bitmap maze = Tree.GetMaze(type);
            List <List <bool> > convertedMaze = Tree.ConvertMazeToBool(maze, type);

            return(Tree.BuildTree(convertedMaze));
        }
コード例 #3
0
        public override string ToString()
        {
            List <string> stats = new List <string>();

            stats.Add(Environment.NewLine);
            stats.Add("==== Maze name : " + MazeType.ToString() + " ====");
            stats.Add("- maze conversion time : " + ConvertingImageToBoolArrayTime.ToString("mm':'ss'.'fff"));
            stats.Add("- size : " + MazeSize.Width + "x" + MazeSize.Height + "px (" + MazeSize.Width * MazeSize.Height + "px)");
            stats.Add("- corridor : " + CorridorSpaces + " (" + MazeProportionOfCorridor.ToString() + "% of maze size)");
            stats.Add("**** Tree ****");
            stats.Add("- number of cells : " + TreeNumberOfCells + " (" + 100 * TreeNumberOfCells / CorridorSpaces + "% of corridor)");
            stats.Add("- build time : " + TreeBuildTime.ToString("mm':'ss'.'fff"));
            stats.Add("- image building time : " + TreeImageBuildTime.ToString("mm':'ss'.'fff"));
            stats.Add("**** Solvers ****");
            foreach (SolverStats solverStats in SolverStats)
            {
                stats.Add("---- Solver : " + solverStats.SolverType + " ----");
                stats.Add("- number of nodes : " + solverStats.NumberOfNodeInSolution);
                stats.Add("- path length : " + solverStats.PathLength);
                stats.Add("- solving time : " + solverStats.SolvingTime.ToString("mm':'ss'.'fff"));
                stats.Add("- image build time : " + solverStats.ResultImageBuildTime.ToString("mm':'ss'.'fff"));
            }

            return(string.Join(Environment.NewLine, stats));
        }
コード例 #4
0
        private void Button_OK_Click(object sender, RoutedEventArgs e)
        {
            if (!int.TryParse(textHeight.Text, out height))
            {
                MessageBox.Show("高度值非法!");
                return;
            }
            if (height <= 0 && height > 99)
            {
                MessageBox.Show("高度值非法!");
                return;
            }
            if (!int.TryParse(textWidth.Text, out width))
            {
                MessageBox.Show("宽度值非法!");
                return;
            }
            if (width <= 0 && width > 99)
            {
                MessageBox.Show("宽度值非法!");
                return;
            }

            mazeType     = (MazeType)cbType.SelectedIndex;
            DialogResult = true;
            Close();
        }
コード例 #5
0
ファイル: ScreenshotManager.cs プロジェクト: mmax-er/Dimaze
    //void SaveSequenceStep()
    //{
    //    SequenceStep step = new SequenceStep();
    //    step.w = int.Parse(uiManager.inputWidth.text);
    //    step.h = int.Parse(uiManager.inputHeight.text);
    //    step.startPos = startPoint.position;
    //    step.endPos = endPoint.position;

    //    if (uiManager.toggleMaze[0].isOn)
    //    {
    //        step.maze = 1;
    //    }
    //    else if (uiManager.toggleMaze[1].isOn)
    //    {
    //        step.maze = 2;

    //    }
    //    else if (uiManager.toggleMaze[2].isOn)
    //    {
    //        step.maze = 3;
    //    }

    //    if (uiManager.togglePath[0].isOn)
    //    {
    //        step.path = 1;
    //    }
    //    else if (uiManager.togglePath[1].isOn)
    //    {
    //        step.path = 2;

    //    }
    //    else if (uiManager.togglePath[2].isOn)
    //    {
    //        step.path = 3;
    //    }

    //    sequence.Add(step);
    //}

    string GetImageName(MazeType maze, PathType path, int size)
    {
        string name = string.Format("{0}_{1}_{2}x{2}.png", maze.ToString(), path.ToString(), size);

        Debug.Log(name);
        return(name);
    }
コード例 #6
0
        /// <summary>
        /// Generates a new maze with a random layout.
        /// </summary>
        /// <param name="mazeType">Type of maze to generate.</param>
        /// <param name="size">Width and height of maze dimensions.</param>
        public static IMaze NewMaze(MazeType mazeType, int size)
        {
            IMazeFactory     mf = new MazeFactory();
            IRandomGenerator rg = new RandomGenerator();

            return(mf.Create(rg, mazeType, size));
        }
コード例 #7
0
ファイル: TestTree.cs プロジェクト: Maelidrem/Dojo
        public void MazeToTree(MazeType type)
        {
            Bitmap maze = Tree.GetMaze(type);
            List <List <bool> > convertedMaze = Tree.ConvertMazeToBool(maze, type);
            List <Cell>         tree          = Tree.BuildTree(convertedMaze);

            Assert.Pass();
        }
コード例 #8
0
        public IMaze Create(IRandomGenerator random, MazeType mazeType, int size)
        {
            IRoomFactory rf = new RoomFactory();

            IRoom[] rooms = new IRoom[size * size];

            for (int i = 0; i < rooms.Length; i++)
            {
                rooms[i] = rf.Create(RoomType.Marsh);
            }
            return(new VerySimpleMaze(size, rooms, 0, rooms.Length - 1));
        }
コード例 #9
0
        public List <Figure> CreateMazeFromTextFile(string filePath)
        {
            if (filePath.Equals(""))
            {
                filePath = @"E:\StandardFile.txt";
            }
            figureList = new List <Figure>();
            TextFileParser parser      = new TextFileParser();
            bool           isFirstLine = true;

            Dictionary <int, string[]> dict = parser.CreateStringDictionary(filePath);

            if (dict == null)
            {
                return(null);
            }

            for (int i = 0; i < dict.Count; i++)
            {
                if (isFirstLine == true)
                {
                    maze          = mazeTypeConverter[dict[0].First()];
                    factoryObject = mazeList[maze].getInstance();
                    isFirstLine   = false;
                    continue;
                }
                else
                {
                    string[] param = dict[i];
                    if (param[0].Equals("Room"))
                    {
                        factoryObject.AddRoom(param, figureList);
                    }
                    else if (param[0].Equals("Corritage"))
                    {
                        factoryObject.AddCorritage(param, figureList);
                    }
                    else if (param[0].Equals("Key") && maze == MazeType.MAGIC)
                    {
                        KeyCounter++;
                        factoryObject.AddKey(param, figureList);
                    }
                    else if (param[0].Equals("MagicRoom") && maze == MazeType.MAGIC)
                    {
                        factoryObject.AddRoom(param, figureList);
                    }
                }
            }
            return(figureList);
        }
コード例 #10
0
ファイル: MazeGenerator.cs プロジェクト: TylerBoyes/MazePlat
	// Use this for initialization
	void Start ()
    {


        Edge.Seed = Seed;
        Edge.SeedIncrement = SeedIncrement;
        cells = new MazeNode[MazeSizeX, MazeSizeY];

        CreateCellArray();

        PopulateCellConnections();

        if (MazeType == "MinTree" || MazeType == "MinimumSpanningTree")
        {
            mazeType = new MinimumSpanningTree();
        }
        else if (MazeType == "Prims")
        {
            mazeType = new Prims();
        }
        else
        {
            mazeType = new DefaultMazeType();
        }
        mazeType.GenerateMaze(cells);

        BuildMaze();
        //BuildMazeArray();

        //we need to set the players position :)
        float startX = MazeSizeY % 2 == 0 ? 2 : 0;
        float startY = ((MazeSizeY - 1) * (CELL_SIZE - 1) - 2) * BLOCK_SIZE;
        Vector3 startPos = new Vector3(startX, startY, 0);
        Player.transform.position = startPos;

        //add entrance door

        GameObject entranceDoor = (GameObject)Instantiate(Resources.Load(DoorPrefab));
        entranceDoor.transform.position = startPos;
        SceneDoor sceneDoor = entranceDoor.GetComponent<SceneDoor>();
        if (GameWideVariables.mazeArguments == "ReturnPoint")
        {
            sceneDoor.location = GameWideVariables.entryDoorLocation;
            sceneDoor.NextLevel = GameWideVariables.entryDoorDestination;
            sceneDoor.Arguments = "SpawnAt";
        }
        GameWideVariables.mazeArguments = "";
        GameWideVariables.entryDoorLocation = Vector2.zero;
        GameWideVariables.entryDoorDestination = "";
    }
コード例 #11
0
        public IMaze Create(IRandomGenerator random, MazeType mazeType, int size)
        {
            if (random is null)
            {
                throw new ArgumentNullException();
            }
            switch (mazeType)
            {
            case MazeType.VerySimpleMaze:
                var(rooms, startIndex, endIndex) = new MazeGenerator().GenerateMaze(random, size);
                return(new VerySimpleMaze(size, rooms, startIndex, endIndex));

            default:
                throw new InvalidMazeTypeException(message: $"Invalid MazeType: {mazeType}");
            }
        }
コード例 #12
0
        private void Menu_NewGame_Click(object sender, RoutedEventArgs e)
        {
            NewGameWin newWin = new NewGameWin();

            if (newWin.ShowDialog() == true)
            {
                _gameSizeH = newWin.GameHeight;
                _gameSizeW = newWin.GameWidth;
                _mazeType  = newWin.MazeType;
                _mazeGame  = new MazeGameModel(_gameSizeH, _gameSizeW);
                _mazeGame.CreateMaze(_factory, _mazeType);
                _mazeGame.Man.SetParam(_roomHeight, _roomWidth);
                SiteType[][] view = _mazeGame.GetView();
                //for (int i = 0; i < view.Count(); i++)
                //	Console.WriteLine(view[i].ToIntString());

                DrawingMaze();
            }
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: AlanEmersic/Mazes-CSharp
        static G RandomMazeType <G>(int size, int seed) where G : Grid
        {
            Random random = new Random(seed);

            mazeType = (MazeType)random.Next(Enum.GetNames(typeof(MazeType)).Length);
            Console.WriteLine(mazeType);
            switch (mazeType)
            {
            case MazeType.Grid: return(new Grid(size, size, seed) as G);

            case MazeType.Polar: return(new PolarGrid(size, seed) as G);

            case MazeType.Hex: return(new HexGrid(size, size, seed) as G);

            case MazeType.Triangle: return(new TriangleGrid(size, size + 5, seed) as G);
            }

            return(null);
        }
コード例 #14
0
ファイル: Tree.cs プロジェクト: Maelidrem/Dojo
        public static List <List <bool> > ConvertMazeToBool(Bitmap maze, MazeType type)
        {
            List <List <bool> > mazeBool = new List <List <bool> >();

            for (int y = 0; y < maze.Size.Height; y++)
            {
                mazeBool.Add(new List <bool>());
                if (type == MazeType.Braid2k)
                {
                    mazeBool[y].Add(false);
                }

                for (int x = 0; x < maze.Size.Width; x++)
                {
                    mazeBool[y].Add(maze.GetPixel(x, y) == CoolColor);
                }
            }

            return(mazeBool);
        }
コード例 #15
0
    /// <summary>
    /// Grid constructor, sets the width and the height and fills the <see cref="Grid.grid"/> array
    /// </summary>
    /// <param name="width">Width of the grid</param>
    /// <param name="height">Height of the grid</param>
    public Grid(int width, int height, MazeType type)
    {
        this.width            = width;
        this.height           = height;
        this.currentAlgorithm = type;

        grid = new Cell[width, height];

        ComputeCells();

        algorithms = new MazeAlgorithm[] {
            MazeUtil.GenerateDepthFirst,
            MazeUtil.GeneratePrim,
            MazeUtil.GenerateBinaryTree,
            MazeUtil.GenerateSideWinder,
            MazeUtil.GenerateKruskal
        };

        algorithms[(int)currentAlgorithm].Invoke(this);
    }
コード例 #16
0
ファイル: Tree.cs プロジェクト: Maelidrem/Dojo
        public static Bitmap GetMaze(MazeType type)
        {
            switch (type)
            {
            case MazeType.Tiny:
                return(Resource.tiny);

            case MazeType.Small:
                return(Resource.small);

            case MazeType.Normal:
                return(Resource.normal);

            case MazeType.Braid200:
                return(Resource.braid200);

            case MazeType.Braid2k:
                return(Resource.braid2k);

            case MazeType.Combo400:
                return(Resource.combo400);

            case MazeType.Combo6k:
                return(Resource.combo6k);

            case MazeType.Perfect10k:
                return(Resource.perfect10k);

            case MazeType.Perfect15k:
                return(Resource.perfect15k);

            case MazeType.Perfect2k:
                return(Resource.perfect2k);

            case MazeType.Perfect4k:
                return(Resource.perfect4k);
            }

            return(null);
        }
コード例 #17
0
        public virtual Maze MakeMaze(int gameSizeH, int gameSizeW, MazeType mazeType = MazeType.Default)
        {
            Maze maze = null;

            switch (mazeType)
            {
            case MazeType.Default:
                maze = new Maze(gameSizeH, gameSizeW);
                break;

            case MazeType.Prime:
                maze = new MazePrime(gameSizeH, gameSizeW);
                break;

            default:
                break;
            }
            maze.InitialRooms(this);
            maze.GenWalls(this);
            maze.GenBorderCharView();
            return(maze);
        }
コード例 #18
0
        public void CreateMaze(MazeFactory factory, MazeType mazeType = MazeType.Prime)
        {
            _maze = factory.MakeMaze(_gameSizeH, _gameSizeW, mazeType);

            SetGameParameters();
        }
コード例 #19
0
ファイル: TestTree.cs プロジェクト: Maelidrem/Dojo
        public void MazeLoading(MazeType type)
        {
            Bitmap maze = Tree.GetMaze(type);

            Assert.Pass();
        }
コード例 #20
0
ファイル: Generator.cs プロジェクト: Craydel/DM_UBER_TOOL
    /// <summary>
    /// Generates a specified maze style at the specified percent cells used (for applicable maze types).
    /// </summary>
    /// <param name="width"></param>
    /// <param name="height"></param>
    /// <param name="pathWidth"></param>
    /// <param name="type"></param>
    /// <param name="percentFull"></param>
    /// <returns></returns>
    public static FloorTile[,] GenerateMaze( int width, int height, int pathWidth, MazeType type, float percentFull )
    {
      // colors for bitmap - used to draw the minimap for each generated maze
      TileColor = new Color[Enum.GetValues(typeof(FloorType)).Length];
      TileColor[(int)FloorType.DoorClosed] = Color.Brown;
      TileColor[(int)FloorType.DoorOpen] = Color.Tan;

      TileColor[(int)FloorType.Wall] = Color.DarkGray;
      TileColor[(int)FloorType.DoorSecret] = Color.DarkGray;

      TileColor[(int)FloorType.Floor] = Color.BlanchedAlmond;
      TileColor[(int)FloorType.Trap] = Color.BlanchedAlmond;

      TileColor[(int)FloorType.StairsDown] = Color.Green;
      TileColor[(int)FloorType.StairsUp] = Color.DarkGreen;

      switch( type )
      {
        case MazeType.HexTunneler:
          return GenerateStyle_HexTunneler(width, height, pathWidth, percentFull);

        case MazeType.SubDivision:
          return GenerateStyle_Subdivision(width, height, pathWidth, percentFull);

        case MazeType.WallAdder:
          return GenerateStyle_WallAdder(width, height, pathWidth);

        case MazeType.Dungeon:
          return GenerateStyle_Dungeon(width, height, pathWidth);

        case MazeType.Castle:
          return GenerateStyle_Castle(width, height, pathWidth, percentFull);

        case MazeType.CircularTunneler:
          return GenerateStyle_CircularTunneler(width, height, pathWidth, percentFull);

        case MazeType.Fracture:
          return GenerateStyle_Fracture(width, height, pathWidth);

        default:
          return GenerateStyle_Tunneler(width, height, pathWidth, percentFull);
      }
    }
コード例 #21
0
ファイル: Generator.cs プロジェクト: Craydel/DM_UBER_TOOL
 /// <summary>
 /// Generates a specified maze style at 100% cells used
 /// </summary>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="pathWidth"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static FloorTile[,] GenerateMaze( int width, int height, int pathWidth, MazeType type )
 {
   return GenerateMaze(width, height, pathWidth, type, 1.0f);
 }
コード例 #22
0
 /// <summary>
 /// Set a new algorithm for the maze
 /// </summary>
 /// <param name="type"></param>
 public void SetMazeType(MazeType type)
 {
     grid.currentAlgorithm = type;
     Reset();
 }
コード例 #23
0
ファイル: Mazerator.cs プロジェクト: shmykov-git/Algo
 public static Shape MakeMaze(Shape shape, int seed = 0, MazeType type = MazeType.SimpleRandom, (int i, int j)[] exits = null, bool openExits = true)
コード例 #24
0
ファイル: Mazes.cs プロジェクト: shmykov-git/Algo
 public static Shape CrateKershner8Maze(double tileLen, double angleD, double rotationAngle, int seed = 0, MazeType type = MazeType.SimpleRandom)
 {
     return(Parquets.PentagonalKershner8(tileLen, angleD).Rotate(rotationAngle).ToShape3().ToMaze(seed, type, new[] { (6, 7), (-6, -5) }));