public void ExecutePathSolver() { PathNode[,] graph = CreateNodeGraph(10, 10); PathSolver solver = new PathSolver(); AStarResult result = solver.Solve(graph[2, 2], graph[8, 8]); Assert.AreEqual(true, result.IsSuccess); Assert.AreEqual(graph[8, 8], result.Result.Last.Value); }
public void ExecutePathSolver_Unsolvable() { PathNode[,] graph = CreateNodeGraph(10, 10); for (int i = 0; i < 10; ++i) { graph[5, i].Connections = new Interfaces.IAStarNodeConnection[0]; } PathSolver solver = new PathSolver(); AStarResult result = solver.Solve(graph[2, 2], graph[8, 8]); Assert.AreEqual(false, result.IsSuccess); Assert.AreEqual(graph[5, 8], result.Result.Last.Value); }
void DoAStar(IntPoint3 src, IntPoint3 dst) { long startBytes, stopBytes; Stopwatch sw = new Stopwatch(); startBytes = GC.GetTotalMemory(true); sw.Start(); if (!this.Step) { m_result = AStarFinder.Find(this, src, this.SrcPos, dst, this.DstPos); sw.Stop(); stopBytes = GC.GetTotalMemory(true); this.MemUsed = stopBytes - startBytes; this.TicksUsed = sw.ElapsedTicks; this.Status = m_result.Status; m_nodes = m_result.Nodes; if (m_result.Status != AStarStatus.Found) { m_path = null; this.PathLength = 0; return; } var pathList = new List<IntPoint3>(); var n = m_result.LastNode; while (n.Parent != null) { pathList.Add(n.Loc); n = n.Parent; } m_path = pathList; this.PathLength = m_result.GetPathReverse().Count(); if (AStarDone != null) AStarDone(m_result); InvalidateTileData(); } else { m_contEvent.Reset(); Task.Factory.StartNew(() => m_result = AStarFinder.Find(this, src, this.SrcPos, dst, this.DstPos)) .ContinueWith((task) => { sw.Stop(); stopBytes = GC.GetTotalMemory(true); this.MemUsed = stopBytes - startBytes; this.TicksUsed = sw.ElapsedTicks; this.Status = m_result.Status; m_nodes = m_result.Nodes; if (m_result.Status != AStarStatus.Found) { m_path = null; this.PathLength = 0; return; } var pathList = new List<IntPoint3>(); var n = m_result.LastNode; while (n.Parent != null) { pathList.Add(n.Loc); n = n.Parent; } m_path = pathList; this.PathLength = m_result.GetPathReverse().Count(); if (AStarDone != null) AStarDone(m_result); InvalidateTileData(); }, TaskScheduler.FromCurrentSynchronizationContext()); } }
void m_map_AStarDone(AStarResult res) { var l = res.LastNode.Loc; var dirs = res.GetPathReverse(); m_path1.Points.Clear(); IntPoint2 p = new IntPoint2(l.X, l.Y); m_path1.Points.Add(new Point(p.X, p.Y)); foreach (var d in dirs) { var v = IntVector2.FromDirection(d); p += v; m_path1.Points.Add(new Point(p.X, p.Y)); } SetZ(m_path1, l.Z); }
void ClearMap() { m_path = null; m_result = null; m_nodes = null; InvalidateTileData(); }