public List<City> GetCityState() { CityService cs=new CityService(); List<City> cityList = cs.GetAll(); City[] vexs = cityList.ToArray(); EData[] edges = cs.GetAllRelation(); // 采用已有的"图" var pG = new ListUdg(vexs, edges); int[] prev = new int[pG.MVexs.Length]; int[] dist = new int[pG.MVexs.Length]; pG.Dijkstra(vexs.ToList().FindIndex(x => x.Name == "洛阳"), prev, dist); foreach (var city in cityList) { if (city.X != 0 && city.Y != 0) { string color=_dm.GetColor(city.X,city.Y); if (color == "ee4814") city.BelongTo=BelongTo.蜀国城池; else if (color == "1da5f1") city.BelongTo=BelongTo.魏国城池; else if (color == "5ad543") city.BelongTo=BelongTo.吴国城池; else city.BelongTo = BelongTo.无法识别; city.State = State.未识别; int index = vexs.ToList().FindIndex(x => x.Name == city.Name); city.Distance = dist[index]; city.PrevCity = prev[index] == 0 ? null : vexs[prev[index]]; } } #region 输出城池归属 //var aa = cityList.Where(c => c.X != 0).Where(x => x.BelongTo == BelongTo.魏国城池).ToList(); //var bb = cityList.Where(c => c.X != 0).Where(x => x.BelongTo == BelongTo.吴国城池).ToList(); //var ccd = cityList.Where(c => c.X != 0).Where(x => x.BelongTo == BelongTo.蜀国城池).ToList(); //Debug.WriteLine("魏国城池:"); //foreach (var city3 in aa) //{ // Debug.Write(city3.Name + "|"); //} //Debug.WriteLine(""); //Debug.WriteLine("吴国城池:"); //foreach (var city1 in bb) //{ // Debug.Write(city1.Name + "|"); //} //Debug.WriteLine(""); //Debug.WriteLine("蜀国城池"); //foreach (var city2 in ccd) //{ // Debug.Write(city2.Name + "|"); //} //Debug.WriteLine(""); #endregion // _dm.Delay(1000); return cityList; }