static void NotFoundPoint(PathNode tempStart, Place end, PathNode node) { node.ParentNode = tempStart; node.G = CalcG(node); node.H = (int)Draw.ComparePoints(end.Coordinate, node.Place.Coordinate); node.F = node.G + node.H; openPathList.Add(node); }
/// <summary> /// 判断计算点并放入openlist中 /// </summary> /// <param name="place">需判断的点</param> /// <param name="parentNode">父对象</param> /// <param name="endNode">终点</param> static void FindAroundNodeToOpenList(Place place, PathNode parentNode, PathNode endNode) { //List<Place> places = Draw.GetAroundPlaceList(Globle.AllPlaceList, pathNode.Place); PathNode pathNode = new PathNode(place); if (openPathList.Exists(obj => obj.Place == place) || closePathList.Exists(obj => obj.Place == place))//已在相关列表中 { return; } pathNode.ParentNode = parentNode; //赋值父对象 pathNode.G = parentNode.G + place.DistrictList.Sum(obj => obj.CrossingTime); //父对象的G加上自身的G pathNode.H = (int)Draw.ComparePoints(place.Coordinate, endNode.Place.Coordinate); //算图上直线距离 pathNode.F = pathNode.G + pathNode.H; openPathList.Add(pathNode); }
/// <summary> /// 找到最短路径的place /// </summary> /// <returns></returns> static Place MinPlace(List <Place> openList, Place endPlace) { Place place = null; foreach (Place item in openList) { //int parentG = 0; //if (item.ParentPlace != null) //{ // parentG = item.DistrictList.Sum(obj => obj.CrossingTime); //} int G = item.DistrictList.Sum(obj => obj.CrossingTime) /*+ parentG*/; int H = (int)Draw.ComparePoints(item.Coordinate, endPlace.Coordinate); int F = G + H; if (place == null || place.DistrictList.Sum(obj => obj.CrossingTime) + (int)Draw.ComparePoints(place.Coordinate, endPlace.Coordinate) > F) { place = item; } } return(place); }