示例#1
0
文件: Maze.cs 项目: pmlocke/Minotaur
        private void ParseMazeFile(string mazeFilePath)
        {
            StreamReader sr   = new StreamReader(mazeFilePath);
            int          x    = 0;
            int          y    = 0;
            string       line = string.Empty;

            while ((line = sr.ReadLine()) != null)
            {
                foreach (char c in line)
                {
                    Debug.Write(c);
                    MazeTile mt = new MazeTile(x, y, Maze.ParseTile("wall", c));
                    if (Maze.ParseTile("start", c))
                    {
                        Start = mt;
                    }
                    if (Maze.ParseTile("finish", c))
                    {
                        Finish = mt;
                    }
                    Layout.Add(mt);
                    x++;
                }
                y++;
                x = 0;
                Debug.Write("\n");
            }
        }
示例#2
0
文件: Maze.cs 项目: pmlocke/Minotaur
        public MazeTile GetTile(int X, int Y)
        {
            MazeTile mt = new MazeTile();

            mt = Layout.Single(t => t.X == X && t.Y == Y);
            return(mt);
        }
示例#3
0
        /// <summary>
        /// Move to an ajacent tile following this priority:
        /// - You have no other option
        /// - You have visited it less than another option
        /// - It is closer to the exit than an equally visited option
        /// - Randomly
        /// </summary>
        /// <param name="theMaze"></param>
        /// <returns></returns>
        private MazeTile ChooseNextLocation(Maze theMaze)
        {
            var nextTile = new MazeTile();
            var choices  = this.LookAround(theMaze);

            choices.RemoveAll(c => c.isWall);

            //Stuck - return an invalid tile to kill the maze.
            if (choices.Count == 0)
            {
                return(nextTile);
            }

            //Dead End - kill this tile
            if (choices.Count == 1)
            {
                CurrentTile.isWall = true;
                return(choices[0]);
            }

            FilterByLeastVisited(choices);
            FilterByLeastDistance(choices);
            nextTile = ChooseRandom(choices);

            return(nextTile);
        }
示例#4
0
        public bool Solve(Maze theMaze)
        {
            InitVisitedList(theMaze);

            this.CurrentTile = theMaze.Start;
            this._Exit = IKnowExitCoordinates ? theMaze.Finish : null;
            this.Move(theMaze);

            return true;
        }
示例#5
0
        public bool Solve(Maze theMaze)
        {
            InitVisitedList(theMaze);

            this.CurrentTile = theMaze.Start;
            this._Exit       = IKnowExitCoordinates ? theMaze.Finish : null;
            this.Move(theMaze);

            return(true);
        }
示例#6
0
 private bool MoveToNextLocation(MazeTile Next)
 {
     if (!Next.isValid)
     {
         return(false);
     }
     PreviousTile = CurrentTile;
     CurrentTile  = Next;
     _Visited[CurrentTile]++;
     return(true);
 }
示例#7
0
文件: Maze.cs 项目: pmlocke/Minotaur
        public Maze(string mazeFilePath)
        {
            Layout = new List <MazeTile>();
            Start  = new MazeTile();
            Finish = new MazeTile();

            ParseMazeFile(mazeFilePath);

            if (!this.Start.isValid || !this.Finish.isValid)
            {
                throw new Exception("Maze must contain a Start and Finish tile.");
            }
        }
示例#8
0
文件: Maze.cs 项目: pmlocke/Minotaur
        public Maze(string mazeFilePath)
        {
            Layout = new List<MazeTile>();
            Start = new MazeTile();
            Finish = new MazeTile();

            ParseMazeFile(mazeFilePath);

            if (!this.Start.isValid || !this.Finish.isValid )
            {
                throw new Exception("Maze must contain a Start and Finish tile.");
            }
        }
示例#9
0
        private void Move(Maze theMaze)
        {
            //From Current Location
            MazeTile Next = this.ChooseNextLocation(theMaze);

            if (!this.MoveToNextLocation(Next))
            {
                throw new Exception("No path exists between start and finish.");
            }

            if (Moved != null)
            {
                Moved(this, new EventArgs());
            }
            if (!CurrentTile.Equals(theMaze.Finish))
            {
                this.Move(theMaze);
            }
        }
示例#10
0
        /// <summary>
        /// Move to an ajacent tile following this priority:
        /// - You have no other option
        /// - You have visited it less than another option
        /// - It is closer to the exit than an equally visited option
        /// - Randomly
        /// </summary>
        /// <param name="theMaze"></param>
        /// <returns></returns>
        private MazeTile ChooseNextLocation(Maze theMaze)
        {
            var nextTile = new MazeTile();
               var choices =  this.LookAround(theMaze);

               choices.RemoveAll(c => c.isWall);

               //Stuck - return an invalid tile to kill the maze.
               if (choices.Count == 0) { return nextTile; }

               //Dead End - kill this tile
               if (choices.Count == 1) {
               CurrentTile.isWall = true;
               return choices[0];
               }

               FilterByLeastVisited(choices);
               FilterByLeastDistance(choices);
               nextTile = ChooseRandom(choices);

               return nextTile;
        }
示例#11
0
文件: Maze.cs 项目: pmlocke/Minotaur
        private void ParseMazeFile(string mazeFilePath)
        {
            StreamReader sr = new StreamReader(mazeFilePath);
            int x = 0;
            int y = 0;
            string line = string.Empty;

            while ((line = sr.ReadLine()) != null)
            {
                foreach (char c in line)
                {
                    Debug.Write(c);
                    MazeTile mt = new MazeTile(x, y, Maze.ParseTile("wall", c));
                    if (Maze.ParseTile("start", c)) { Start = mt; }
                    if (Maze.ParseTile("finish", c)) { Finish = mt; }
                    Layout.Add(mt);
                    x++;
                }
                y++;
                x = 0;
                Debug.Write("\n");
            }
        }
示例#12
0
 private bool MoveToNextLocation(MazeTile Next)
 {
     if (!Next.isValid) { return false; }
     PreviousTile = CurrentTile;
     CurrentTile = Next;
     _Visited[CurrentTile]++;
     return true;
 }
示例#13
0
文件: Maze.cs 项目: pmlocke/Minotaur
 public MazeTile GetTile(int X, int Y)
 {
     MazeTile mt = new MazeTile();
     mt = Layout.Single(t => t.X == X && t.Y == Y);
     return mt;
 }