Esempio n. 1
0
        private void btn_findPath_Click(object sender, EventArgs e)
        {
            if (points.Count != 2)
            {
                MessageBox.Show("Please select start point and end point!");
                return;
            }
            var       start     = points[0];
            var       end       = points[1];
            Stopwatch stopwatch = new Stopwatch();

            AutoRoute autoRoute = new AutoRoute((int[, ])readMap.Maze.Clone());

            stopwatch.Start();
            var tempPoints = autoRoute.FindeWay(start, end);

            stopwatch.Stop();
            if (tempPoints == null || tempPoints.Count == 0)
            {
                lbl_info.Text = "Can't find the path!";
                return;
            }
            lbl_info.Text = $"times:{stopwatch.ElapsedMilliseconds}\r\nDistance:{tempPoints.Count}";

            var newBitmap = (Bitmap)readMap.clippingZone.Clone();

            pic_map.Image = newBitmap;

            foreach (var item in tempPoints)
            {
                newBitmap.SetPixel(item.X, item.Y, Color.Red);
            }
            pic_map.Image = newBitmap;
        }
Esempio n. 2
0
        /// <summary>
        /// 寻路
        /// </summary>
        /// <param name="position"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        protected ActionResult <List <Point> > FindPath(PositionInfo position, Point to)
        {
            ReadMap readMap = new ReadMap();

            readMap.mapFile = @"F:\Program Files\ShengquGames\Legend of mir\Map\3.map";
            readMap.Load();

            MirContext.ReadMap = readMap;

            AutoRoute autoRoute = new AutoRoute((int[, ])readMap.Maze.Clone());

            var tempPoints = autoRoute.FindeWay(to, position.Point);

            return(new ActionResult <List <Point> >(tempPoints));
            //PathGrid pathGrid = new PathGrid(MirContext.ReadMap.Width, MirContext.ReadMap.Height, MirContext.Maze(position.MapInfo));
            //return new ActionResult<List<Point>>(pathGrid.FindPath(position.Point, to));
        }