Example #1
0
        int GenerateMode;          // 迷路の生成モード 1:棒倒し法

        //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
        //
        // 隣接リストは[NodeID,{上隣接,右隣接,下隣接,左隣接}]の構造
        //________________________________________________________________
        // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /

        //----------------------
        //    コンストラクタ
        //----------------------
        public Board(int height, int width, int mode)
        {
            // 引数から迷路のサイズを決定する
            MazeHeight   = height;
            MazeWidth    = width;
            NodeNumber   = MazeHeight * MazeWidth;
            MazeNode     = new List <Node>();
            GenerateMode = mode;

            // 隣接リスト
            AdjacencyList = new int[NodeNumber, 4];

            // ノードを作成
            int id = 0;

            for (int i = 0; i < MazeHeight; i++)
            {
                for (int j = 0; j < MazeWidth; j++)
                {
                    // リストに生成したノードを格納
                    MazeNode.Add(new Node(id++, j * SysCon.CellSize, i * SysCon.CellSize));
                }
            }
            // 隣接リストの生成
            switch (SysCon.GenerateMode)
            {
            case 0:
                AdjacencyList = MazeGenerator.StabCollapse(NodeNumber, MazeWidth, MazeHeight);
                break;

            case 1:
                AdjacencyList = MazeGenerator.Clustering(NodeNumber, MazeWidth, MazeHeight);
                break;
            }
        }
Example #2
0
        public void ChangeGenerationAlgorithm(GenerationAlgorithmEnum generationAlgorithm)
        {
            switch (generationAlgorithm)
            {
            case GenerationAlgorithmEnum.RecursiveBacktracker:
            {
                _mazeGenerator = new RecursiveBacktrackerMazeGenerator();
            }
            break;

            default:
                throw new Exception("Generation algorithm is not found");
            }
            _generationAlgorithm = generationAlgorithm;
        }
Example #3
0
        private void Awake()
        {
            mazeGenerator   = GetComponent <MazeGenerator>();
            playerGenerator = GetComponent <PlayerGenerator>();
            itemGenerator   = GetComponent <ItemGenerator>();
            playerManager   = GetComponent <PlayerManager>();
            var managers = GameObject.FindWithTag("Managers");

            turnManager = managers.GetComponent <TurnManager>();

            var buttons = GetComponent <Buttons>();

            buttons.moveColumn?.onClick.AddListener(MoveColumn);

            actions = new Actions();
        }
Example #4
0
        private void makePlain(int layer)
        {
            MazeGenerator mazeGenerator = new MazeGenerator();

            mazeGenerator.Start_CreatMaze((WidthX + 1) / 2, (WidthY + 1) / 2);

            List <int> coordinate = new List <int>();

            coordinate = mazeGenerator.maze.All_Coordinate();

            int coordinate_range = coordinate.Count;

            for (int i = 0; i < coordinate_range; i += 2)
            {
                Point3D target = new Point3D(coordinate[i], coordinate[i + 1], layer);
                GetAt(target).InsertObj(new Stone(target));
            }
        }
Example #5
0
 public MazeWindow(Mode mode)
 {
     InitializeComponent();
     this.FormBorderStyle = FormBorderStyle.None;
     gameMode             = mode;
     maze = new Label[WIDTH, HEIGHT];
     MazeGenerator.GenerateMaze();
     createGrid();
     if (gameMode == Mode.Mouse)
     {
         Point startingPoint = maze[1, 1].Location;
         startingPoint.Offset(10, 10);
         Cursor.Position = PointToScreen(startingPoint);
         checkPoint      = PointToScreen(startingPoint);
         timer1.Start();
     }
     else
     {
         this.Text = "The Maze Game - Keyboard Mode";
     }
     this.KeyUp += keyboardControl;
 }
Example #6
0
        //---------------------------
        //      コンストラクタ
        //---------------------------
        public AutomaticSearch(int Height, int Width, int ExecutionTimes, ref TextBox MazeConsole)
        {
            this.ExecutionTimes = ExecutionTimes;
            int[,] AMatrix      = new int[Height * Width, 4];
            MazeHeight          = Height;
            MazeWidth           = Width;
            this.MazeConsole    = MazeConsole;

            // ノードを生成
            int id = 0;

            for (int i = 0; i < MazeHeight; i++)
            {
                for (int j = 0; j < MazeWidth; j++)
                {
                    // リストに生成したノードを格納
                    MazeNode.Add(new Node(id++, j * SysCon.CellSize, i * SysCon.CellSize));
                }
            }

            // 隣接行列の生成
            AMatrix = MazeGenerator.StabCollapse(MazeNode.Count, MazeWidth, MazeHeight);
            sc      = new Searcher(ref MazeNode, AMatrix, 1);
        }
Example #7
0
 public Form1()
 {
     InitializeComponent();
     generator = new Maze.MazeGenerator();
 }
Example #8
0
        //-------------------------
        //     実行メソッド
        //-------------------------
        public void Run()
        {
            // ラベルの表示
            Stopwatch sw = new Stopwatch();

            MazeConsole.AppendText(String.Format("\r\n---- {0}*{1} ----\r\n", MazeHeight, MazeWidth));
            MazeConsole.AppendText(String.Format("Take\tBreadth\tDepth\tA*\tWinner\r\n"));
            MazeConsole.AppendText(String.Format("-------------------------------------------\r\n"));


            int top;                              // 現在の最小展開ノード数
            int flag = 0;                         // どの探索が優秀だったか判断するためのフラグ

            int[]      winnumber = new int[3];    // 勝利数
            double[]   average   = new double[3]; // 平均展開ノード数
            long[]     extime    = new long[3];   // 各Take各アルゴリズム毎の合計Ticks
            long[]     avgtime   = new long[3];   // 各アルゴリズムの平均Ticks
            TimeSpan[] time      = new TimeSpan[3];

            for (int i = 1; i <= ExecutionTimes; i++)
            {
                // 迷路を新たに作成
                switch (SysCon.GenerateMode)
                {
                case 0:
                    AMatrix = MazeGenerator.StabCollapse(MazeNode.Count, MazeWidth, MazeHeight);
                    break;

                case 1:
                    AMatrix = MazeGenerator.Clustering(MazeNode.Count, MazeWidth, MazeHeight);
                    break;
                }

                sc = new Searcher(ref MazeNode, AMatrix, 1);

                // 各探索を実行しながら結果を表示する
                MazeConsole.AppendText(string.Format("Take:{0}\t", i));

                // 幅優先
                sw.Reset();
                sw.Start();
                sc.Breadth();
                sw.Stop();
                extime[0] += sw.ElapsedTicks;
                MazeConsole.AppendText(string.Format("{0}\t", SysCon.OpenCount));
                top         = SysCon.OpenCount;
                average[0] += SysCon.OpenCount;

                // 深さ優先
                sw.Reset();
                sw.Start();
                sc.Depth();
                sw.Stop();
                extime[1] += sw.ElapsedTicks;
                MazeConsole.AppendText(string.Format("{0}\t", SysCon.OpenCount));

                if (SysCon.OpenCount < top)
                {
                    top  = SysCon.OpenCount;
                    flag = 1;
                }
                average[1] += SysCon.OpenCount;

                // A*
                sw.Reset();
                sw.Start();
                sc.Astar();
                sw.Stop();
                extime[2] += sw.ElapsedTicks;
                MazeConsole.AppendText(string.Format("{0}\t", SysCon.OpenCount));

                if (SysCon.OpenCount < top)
                {
                    top  = SysCon.OpenCount;
                    flag = 2;
                }
                average[2] += SysCon.OpenCount;

                // 優秀だった探索法を表示する
                switch (flag)
                {
                case 0:
                    MazeConsole.AppendText("Breadth\r\n");
                    winnumber[0]++;
                    break;

                case 1:
                    MazeConsole.AppendText("Depth\r\n");
                    winnumber[1]++;
                    break;

                case 2:
                    MazeConsole.AppendText("A*\r\n");
                    winnumber[2]++;
                    break;
                }
            }
            // 平均値計算
            for (int i = 0; i < 3; i++)
            {
                average[i] = average[i] / ExecutionTimes;
                avgtime[i] = extime[i] / ExecutionTimes;
                time[i]    = new TimeSpan(avgtime[i]);
            }

            MazeConsole.AppendText(string.Format("\r\nMethod\tWin\tAverage\tRate\tTime\r\n"));
            MazeConsole.AppendText(string.Format("-------------------------------------------------\r\n"));
            MazeConsole.AppendText(string.Format("Breadth\t{0}\t{1}\t{2}%\t{3}\r\n", winnumber[0], average[0].ToString("F1"), ((average[0] / MazeNode.Count) * 100.0).ToString("F1"), time[0]));
            MazeConsole.AppendText(string.Format("Depth\t{0}\t{1}\t{2}%\t{3}\r\n", winnumber[1], average[1].ToString("F1"), ((average[1] / MazeNode.Count) * 100.0).ToString("F1"), time[1]));
            MazeConsole.AppendText(string.Format("A*\t{0}\t{1}\t{2}%\t{3}\r\n", winnumber[2], average[2].ToString("F1"), ((average[2] / MazeNode.Count) * 100.0).ToString("F1"), time[2]));
        }