• 大小: 62KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: C#
  • 标签: A*  

资源简介

A*算法,A*(A-Star)算法是一种静态路网中求解最短路径最有效的直接搜索方法,也是解决许多搜索问题的有效算法。算法中的距离估算值与实际值越接近,最终搜索速度越快。该资源是用WinForm实现的,可以更直接明了的查看到寻路路径

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AStarAlgorithm
{
    public class AStarAlgorithm
    {
        private List openList = new List();
        private List closeList = new List();

        private byte[] map;

        public AStarAlgorithm(byte[] map)
        {
            this.map = map;
        }

        private Point GetMinPoint()
        {
            Point point = null;
            foreach (var item in openList)
            {
                if (point == null || point.G + point.H > item.G + item.H)
                    point = item;
            }
            return point;
        }

        private bool CanReach(int xint y)
        {
            return false;
        }
        private bool CanReach(Point point)
        {
            return map[point.Y point.Y] == 0;
        }

        private int CalcG(Point point)
        {
            if (point.ParentPoint == null) return 0;
            if (point.X == point.ParentPoint.X || point.Y == point.ParentPoint.Y)
                return point.ParentPoint.G + 10;
            else
                return point.ParentPoint.G + 14;
        }
        private int CalcH(Point startPoint Point endPoint)
        {
            return (Math.Abs(endPoint.Y - startPoint.Y) + Math.Abs(endPoint.X - startPoint.X)) * 10;
        }
        private void SurroundPoints(Point point Point startPointref Point endPoint)
        {
             var surroundPoints = new List(9);
            for ( int x = point.X - 1; x <= point.X + 1; x++)
            {
                for (int y = point.Y - 1; y <= point.Y + 1; y++)
                {
                    if ((x >= 0 && x < map.GetLength(0) && y >= 0 && y < map.GetLength(1)) && !(x == point.X && y == point.Y))
                    {
                        bool b = !closeList.Exist(x y);
                        if (map[x y] != 0 &&b )
                        {
                            if (openList.Exist(x y))
                            {
                                Point p = openList.GetPoint(x y);
                                int g = 0;
                                g = point.G + (point.X == p.X || point.Y == p.Y ? 10 : 14);

                                if (g < point.G)
                                {
                                    openList.Remove(p);
                                    p.ParentPoint = point;
                                    p.G = g;
                                    openList.Add(p);
                                }
                            }
                            else
                            {
                                Point p = new Point();
                                p.X = x;
                                p.Y = y;
                                p.ParentPoint = point;
                  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     48128  2018-12-27 17:17  AStarAlgorithm\.vs\AStarAlgorithm\v14\.suo

     文件        189  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\App.config

     文件       4675  2018-12-27 17:09  AStarAlgorithm\AStarAlgorithm\AStarAlgorithm.cs

     文件       4116  2018-12-27 13:34  AStarAlgorithm\AStarAlgorithm\AStarAlgorithm.csproj

     文件      14848  2018-12-27 17:09  AStarAlgorithm\AStarAlgorithm\bin\Debug\AStarAlgorithm.exe

     文件        189  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\bin\Debug\AStarAlgorithm.exe.config

     文件      36352  2018-12-27 17:09  AStarAlgorithm\AStarAlgorithm\bin\Debug\AStarAlgorithm.pdb

     文件      22696  2018-12-27 17:17  AStarAlgorithm\AStarAlgorithm\bin\Debug\AStarAlgorithm.vshost.exe

     文件        189  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\bin\Debug\AStarAlgorithm.vshost.exe.config

     文件       4346  2018-12-27 15:04  AStarAlgorithm\AStarAlgorithm\frm_AStar.cs

     文件       5683  2018-12-27 14:28  AStarAlgorithm\AStarAlgorithm\frm_AStar.Designer.cs

     文件       5817  2018-12-27 14:28  AStarAlgorithm\AStarAlgorithm\frm_AStar.resx

     文件        499  2018-12-27 13:23  AStarAlgorithm\AStarAlgorithm\MyButton.cs

     文件        820  2018-12-27 17:17  AStarAlgorithm\AStarAlgorithm\obj\Debug\AStarAlgorithm.csproj.FileListAbsolute.txt

     文件       1016  2018-12-27 14:28  AStarAlgorithm\AStarAlgorithm\obj\Debug\AStarAlgorithm.csproj.GenerateResource.Cache

     文件       2384  2018-12-27 14:28  AStarAlgorithm\AStarAlgorithm\obj\Debug\AStarAlgorithm.csprojResolveAssemblyReference.cache

     文件      14848  2018-12-27 17:09  AStarAlgorithm\AStarAlgorithm\obj\Debug\AStarAlgorithm.exe

     文件        180  2018-12-27 14:28  AStarAlgorithm\AStarAlgorithm\obj\Debug\AStarAlgorithm.frm_AStar.resources

     文件      36352  2018-12-27 17:09  AStarAlgorithm\AStarAlgorithm\obj\Debug\AStarAlgorithm.pdb

     文件        180  2018-12-27 14:28  AStarAlgorithm\AStarAlgorithm\obj\Debug\AStarAlgorithm.Properties.Resources.resources

     文件        868  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7192  2018-12-27 13:34  AStarAlgorithm\AStarAlgorithm\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件        656  2018-12-27 13:19  AStarAlgorithm\AStarAlgorithm\Point.cs

     文件        530  2018-12-27 13:13  AStarAlgorithm\AStarAlgorithm\Program.cs

     文件       1354  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\Properties\AssemblyInfo.cs

     文件       2841  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\Properties\Resources.Designer.cs

     文件       5612  2018-12-27 13:09  AStarAlgorithm\AStarAlgorithm\Properties\Resources.resx

............此处省略18个文件信息

评论

共有 条评论