예제 #1
0
파일: Mazes.cs 프로젝트: radishes/MazeGUI
        public void SolveStep()
        { // runs once per "frame" of maze solving
            if (this.state < 0)
            {
                return; //error condition
            }
            if (this.alivePoints.Count <= 0)
            { // no solve in progress already, initialize solver
                this.state = 1;
                this.exploredPoints.Add(new ExploredPoint(start, null, 0));
                this.currentGen = 1;
                for (int d = 0; d < 4; d++)
                {
                    alivePoints.Add(new ExploredPoint(MazeTools.MovePoint(start, MazeTools.DirToPoint(d)), exploredPoints.First(), currentGen));
                    this.exploredPoints.Add(new ExploredPoint(MazeTools.MovePoint(start, MazeTools.DirToPoint(d)), exploredPoints.First(), currentGen));
                }
            }

            List <ExploredPoint> nextGenPoints = new List <ExploredPoint>();

            this.currentGen++;

            Stopwatch       stopwatch = Stopwatch.StartNew();
            HashSet <Point> ep        = GetExploredPoints();

            stopwatch.Stop();
            Debug.WriteLine(stopwatch.ElapsedTicks);

            foreach (ExploredPoint node in alivePoints)
            {
                if (MazeTools.ArePointsEqual(node.p, this.end))
                {
                    this.state = 4;
                }

                if (this.state >= 4)
                {
                    break; // found solution
                }
                List <Point> pNeighbors = node.p.GetSurroundingPoints();
                foreach (Point neighbor in pNeighbors)
                {
                    if (MazeTools.ArePointsEqual(node.parent.p, neighbor))
                    {
                        continue;
                    }
//Stopwatch stopwatch = Stopwatch.StartNew();
                    if (ep.Contains(neighbor))
                    {
                        continue;
                    }
//stopwatch.Stop();
//Debug.WriteLine(stopwatch.ElapsedTicks);
                    if (!PeekFunc(neighbor))
                    {
                        // maintaining three separate lists with similar information. this can be fixed up I bet.
                        nextGenPoints.Add(new ExploredPoint(neighbor, node, this.currentGen));
                        this.exploredPoints.Add(new ExploredPoint(neighbor, node, this.currentGen));
                        ep.Add(neighbor); // ugh
                    }
                }
            } // end foreach node in alivePoints

            if (this.state == 4)
            { // solution found; now trace back
                if (solution == null)
                {
                    solution = new List <Point>();
                    ExploredPoint tracer = exploredPoints.Last();
                    while (tracer != exploredPoints.First())
                    {
                        solution.Add(new Point(tracer.p.X, tracer.p.Y));
                        tracer = tracer.parent;
                    }
                    this.state = 12;
                }
            }

            alivePoints = nextGenPoints;

            if (alivePoints.Count <= 0)
            {
                this.state = 8;
            }
        }
예제 #2
0
파일: Mazes.cs 프로젝트: radishes/MazeGUI
        public bool Equals(ExploredPoint other)
        {
            bool b = (this.p == other.p);

            return(b);
        }
예제 #3
0
파일: Mazes.cs 프로젝트: radishes/MazeGUI
 public bool Equals(ExploredPoint other)
 {
     bool b = (this.p == other.p);
     return b;
 }
예제 #4
0
파일: Mazes.cs 프로젝트: radishes/MazeGUI
 public ExploredPoint(Point p, ExploredPoint parent, int generation)
 {
     this.p          = p;
     this.parent     = parent;
     this.generation = generation;
 }
예제 #5
0
파일: Mazes.cs 프로젝트: radishes/MazeGUI
 public ExploredPoint(Point p, ExploredPoint parent, int generation)
 {
     this.p = p;
     this.parent = parent;
     this.generation = generation;
 }