/// <summary> /// 检测地图是连通的 /// </summary> /// <returns></returns> public bool CheckMapIsConnected() { bool isConnected = false; mMapMgr.BuildMap(); List <Node> path = AStarMgr.Instance.FindPath(new Vector2(0, 0), new Vector2(mMapMgr.Width - 1, mMapMgr.Height - 1)); if (path != null && path.Count > 0) { isConnected = true; } return(isConnected); }
private void ClickPathFindingBtn(int times, int count, int mapNum) { List <float> resTimesIn = new List <float>(); List <float> resTimesOut = new List <float>(); Vector2 start = new Vector2(0, 0); Vector2 end = new Vector2(mMapMgr.Width - 1, mMapMgr.Height - 1); //mMapMgr.BuildMap(); List <int> seedList = mRandomMapCreator.GetValidSeedList(mapNum, Probability, RandomSeed, MaxTimes); for (int p = 0; p < seedList.Count; p++) { mRandomMapCreator.Create(seedList[p], Probability); mMapMgr.BuildMap(); for (int j = 0; j < count; j++) { mTimer.Begin(TIMER_KEY_ASTAR_PF); for (int i = 0; i < times; i++) { mAStarMgr.FindPath(start, end); } mTimer.End(TIMER_KEY_ASTAR_PF); resTimesIn.Add(mTimer.GetSumTime(TIMER_KEY_ASTAR_PF)); } resTimesIn.Sort(); float sumTimeIn = 0.0f; for (int i = 1; i <= resTimesIn.Count - 2; i++) { sumTimeIn += resTimesIn[i]; } resTimesOut.Add((sumTimeIn / (resTimesIn.Count - 2)) / times); } resTimesOut.Sort(); float sumTimeOut = 0.0f; for (int i = 1; i <= resTimesOut.Count - 2; i++) { sumTimeOut += resTimesOut[i]; } mFindPathTime = sumTimeOut / (resTimesOut.Count - 2); mPath = mAStarMgr.FindPath(start, end); //mFindPathTime = mTimer.GetSumTime(TIMER_KEY_ASTAR_PF); mFindPathCost = CalculatePathConsume(mPath); SpawnMap(); HTLogger.Debug(string.Format("寻路 {0} 次:{1}毫秒", times, mFindPathTime * times)); HTLogger.Debug(string.Format("寻路 1 次:{0}毫秒", mFindPathTime)); HTLogger.Debug("路径消耗:" + mFindPathCost); }