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; } }
public bool Equals(ExploredPoint other) { bool b = (this.p == other.p); return(b); }
public bool Equals(ExploredPoint other) { bool b = (this.p == other.p); return b; }
public ExploredPoint(Point p, ExploredPoint parent, int generation) { this.p = p; this.parent = parent; this.generation = generation; }