public void AddPoint(DPoint currPoint, DPoint lastPoint, int weight) { checkPoints = new List <DCheckPoint> (); Debug.Log(currPoint.name + " /" + lastPoint.name + "/" + weight); DCheckPoint CP = new DCheckPoint(currPoint, lastPoint, weight); //checkPoints.Add (new DCheckPoint (currPoint,lastPoint,weight)); checkPoints.Add(CP); }
public DCheckPoint GetLessWeight() { DCheckPoint p = new DCheckPoint(); p.weight = 999999999; foreach (DCheckPoint point in checkPoints) { if (p.weight > point.weight) { p = point; } } return(p); }
public List <DPoint> GetPath(DPoint startPoint, DPoint finishPoint) { List <DPoint> way = new List <DPoint> (); List <DCheckPoint> bestCheckPoints = new List <DCheckPoint> (); // List<DIteration> iterations = new List<DIteration>(); DIteration iteration = new DIteration(); iteration.AddPoint(startPoint, startPoint, 0); iterations.Add(iteration); DPoint currPoint = startPoint; while (true) { List <DCheckPoint> CPL = new List <DCheckPoint> (); foreach (DIteration IT in iterations) { DCheckPoint CP = IT.GetLessWeight(); Debug.Log(CP.currPoint.name); //CP = (bestCheckPoints.Find (x => x.currPoint == CP.currPoint)); if (bestCheckPoints.Count == 0) { bestCheckPoints.Add(CP); Debug.Log(bestCheckPoints.Count + "BEST"); } foreach (DCheckPoint y in bestCheckPoints) { if (y.currPoint == CP.currPoint) { Debug.Log("SAME"); break; } else { Debug.Log(CP.currPoint.name); CPL.Add(CP); } } } //CPL.Sort((x, y) => x.weight); //Debug.Log (CPL[0].weight); break; } return(way); }