/// <summary> /// 自动寻路(全地图跑,非传送模式) 例如,from 程海 to 蓬莱 /// </summary> /// <param name="from">从xx地图</param> /// <param name="to">到yy地图</param> /// <param name="s">图片相似度</param> /// <returns></returns> public int WayfindingEx(string from, string to, double s) { //string dtPrefix="地图_"; //string from = "", to = ""; //if (0 == dt1Path.IndexOf(dtPrefix) || 0 == dt2Path.IndexOf(dtPrefix)) //{ // throw new Exception("地图图片名称要以:"+dtPrefix+"开头"); //} //from = dt1Path.ToUpper().Replace("地图_", "").Replace(".BMP",""); //to = dt2Path.ToUpper().Replace("地图_", "").Replace(".BMP", ""); List<ILine> lst_result; RoadFinder finder = new RoadFinder(); if (finder.FindRoad(from, to, lst_lines, out lst_result)) { for (int i = 0; i < lst_result.Count; i++) { TestLine tl = (TestLine)lst_result[i]; CloseSubWindows(); Thread.Sleep(1000); try { Wayfinding("自动寻路_通往" + tl.DstId + ".bmp", "地图_" + tl.DstId + ".bmp", s, 2); } catch (Exception ex) { if (ex.Message.IndexOf("自动寻路_通往" + tl.DstId) != -1) { int x,y; if (1 == GetPicCenter("地图_" + tl.DstId + ".bmp", 0.9, 2, 3, out x, out y)) { continue; } else { if(i>0) i--; } } } } } else { throw new Exception("找不到可行路径:" + from + "-" + to); } return 0; }
/// <summary> /// 测试方法 /// </summary> public static void Test() { List<ILine> lst_lines = new List<ILine>(); //A - B lst_lines.Add(new TestLine("京师", "太子坡", 1)); //B - C lst_lines.Add(new TestLine("京师", "蓬莱", 1)); //C - D lst_lines.Add(new TestLine("蓬莱", "长白山", 1)); lst_lines.Add(new TestLine("长白山", "神龙岛", 1)); lst_lines.Add(new TestLine("神龙岛", "泰山", 1)); lst_lines.Add(new TestLine("泰山", "百花谷", 1)); lst_lines.Add(new TestLine("太子坡", "五台山", 1)); lst_lines.Add(new TestLine("太子坡", "嘉峪关", 1)); lst_lines.Add(new TestLine("嘉峪关", "木兰草原", 1)); lst_lines.Add(new TestLine("木兰草原", "辽西", 1)); lst_lines.Add(new TestLine("木兰草原", "长白山", 1)); lst_lines.Add(new TestLine("嘉峪关", "华山", 1)); lst_lines.Add(new TestLine("五台山", "嵩山", 1)); lst_lines.Add(new TestLine("蓬莱", "王屋山", 1)); lst_lines.Add(new TestLine("王屋山", "百花谷", 1)); lst_lines.Add(new TestLine("华山", "玉龙雪山", 1)); lst_lines.Add(new TestLine("玉龙雪山", "丽江", 1)); lst_lines.Add(new TestLine("丽江", "昆仑山口", 1)); lst_lines.Add(new TestLine("昆仑山口", "天池", 1)); lst_lines.Add(new TestLine("玉龙雪山", "嵩山", 1)); lst_lines.Add(new TestLine("丽江", "南岭", 1)); lst_lines.Add(new TestLine("南岭", "程海", 1)); lst_lines.Add(new TestLine("程海", "昆明", 1)); lst_lines.Add(new TestLine("嵩山", "昆明", 1)); lst_lines.Add(new TestLine("程海", "哀牢山", 1)); lst_lines.Add(new TestLine("哀牢山", "白龙潭", 1)); lst_lines.Add(new TestLine("哀牢山", "黑龙潭", 1)); lst_lines.Add(new TestLine("白龙潭", "扬州", 1)); lst_lines.Add(new TestLine("黑龙潭", "扬州", 1)); lst_lines.Add(new TestLine("白龙潭", "隐龙江", 1)); lst_lines.Add(new TestLine("黑龙潭", "隐龙江", 1)); lst_lines.Add(new TestLine("隐龙江", "武夷山", 1)); lst_lines.Add(new TestLine("武夷山", "南岭", 1)); lst_lines.Add(new TestLine("隐龙江", "龙虎山", 1)); lst_lines.Add(new TestLine("龙虎山", "泰山", 1)); lst_lines.Add(new TestLine("百花谷", "扬州", 1)); lst_lines.Add(new TestLine("百花谷", "古域丛林", 1)); lst_lines.Add(new TestLine("古域丛林", "古域海底", 1)); lst_lines.Add(new TestLine("古域海底", "古域矿洞", 1)); lst_lines.Add(new TestLine("古域矿洞", "古域东宫", 1)); lst_lines.Add(new TestLine("古域东宫", "古域西宫", 1)); //B - D //lst_lines.Add(new TestLine("B", "D", 1)); List<ILine> lst_result; RoadFinder finder = new RoadFinder(); if (finder.FindRoad("蓬莱", "程海", lst_lines, out lst_result)) { foreach (ILine line in lst_result) Console.WriteLine(line); } }
/// <summary> /// 测试方法 /// </summary> public static void Test() { List <ILine> lst_lines = new List <ILine>(); //A - B lst_lines.Add(new TestLine("京师", "太子坡", 1)); //B - C lst_lines.Add(new TestLine("京师", "蓬莱", 1)); //C - D lst_lines.Add(new TestLine("蓬莱", "长白山", 1)); lst_lines.Add(new TestLine("长白山", "神龙岛", 1)); lst_lines.Add(new TestLine("神龙岛", "泰山", 1)); lst_lines.Add(new TestLine("泰山", "百花谷", 1)); lst_lines.Add(new TestLine("太子坡", "五台山", 1)); lst_lines.Add(new TestLine("太子坡", "嘉峪关", 1)); lst_lines.Add(new TestLine("嘉峪关", "木兰草原", 1)); lst_lines.Add(new TestLine("木兰草原", "辽西", 1)); lst_lines.Add(new TestLine("木兰草原", "长白山", 1)); lst_lines.Add(new TestLine("嘉峪关", "华山", 1)); lst_lines.Add(new TestLine("五台山", "嵩山", 1)); lst_lines.Add(new TestLine("蓬莱", "王屋山", 1)); lst_lines.Add(new TestLine("王屋山", "百花谷", 1)); lst_lines.Add(new TestLine("华山", "玉龙雪山", 1)); lst_lines.Add(new TestLine("玉龙雪山", "丽江", 1)); lst_lines.Add(new TestLine("丽江", "昆仑山口", 1)); lst_lines.Add(new TestLine("昆仑山口", "天池", 1)); lst_lines.Add(new TestLine("玉龙雪山", "嵩山", 1)); lst_lines.Add(new TestLine("丽江", "南岭", 1)); lst_lines.Add(new TestLine("南岭", "程海", 1)); lst_lines.Add(new TestLine("程海", "昆明", 1)); lst_lines.Add(new TestLine("嵩山", "昆明", 1)); lst_lines.Add(new TestLine("程海", "哀牢山", 1)); lst_lines.Add(new TestLine("哀牢山", "白龙潭", 1)); lst_lines.Add(new TestLine("哀牢山", "黑龙潭", 1)); lst_lines.Add(new TestLine("白龙潭", "扬州", 1)); lst_lines.Add(new TestLine("黑龙潭", "扬州", 1)); lst_lines.Add(new TestLine("白龙潭", "隐龙江", 1)); lst_lines.Add(new TestLine("黑龙潭", "隐龙江", 1)); lst_lines.Add(new TestLine("隐龙江", "武夷山", 1)); lst_lines.Add(new TestLine("武夷山", "南岭", 1)); lst_lines.Add(new TestLine("隐龙江", "龙虎山", 1)); lst_lines.Add(new TestLine("龙虎山", "泰山", 1)); lst_lines.Add(new TestLine("百花谷", "扬州", 1)); lst_lines.Add(new TestLine("百花谷", "古域丛林", 1)); lst_lines.Add(new TestLine("古域丛林", "古域海底", 1)); lst_lines.Add(new TestLine("古域海底", "古域矿洞", 1)); lst_lines.Add(new TestLine("古域矿洞", "古域东宫", 1)); lst_lines.Add(new TestLine("古域东宫", "古域西宫", 1)); //B - D //lst_lines.Add(new TestLine("B", "D", 1)); List <ILine> lst_result; RoadFinder finder = new RoadFinder(); if (finder.FindRoad("蓬莱", "程海", lst_lines, out lst_result)) { foreach (ILine line in lst_result) { Console.WriteLine(line); } } }