コード例 #1
0
        public JumpPointParam(BaseGrid iGrid, EndNodeUnWalkableTreatment iAllowEndNodeUnWalkable = EndNodeUnWalkableTreatment.ALLOW, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
            : base(iGrid, iMode)
        {
            CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable;

            openList         = new IntervalHeap <Node>();
            CurIterationType = IterationType.LOOP;
        }
コード例 #2
0
        public JumpPointParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, bool iAllowEndNodeUnWalkable = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
            : base(iGrid, iStartPos, iEndPos, iMode)
        {
            CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable ? EndNodeUnWalkableTreatment.ALLOW : EndNodeUnWalkableTreatment.DISALLOW;
            openList = new IntervalHeap <Node>();

            CurIterationType = IterationType.LOOP;
        }
コード例 #3
0
        private void Init()
        {
            DoubleBuffered = true;

            m_resultBox = new List <ResultBox>();
            Width       = (width + 1) * 10;
            Height      = (height + 1) * 10 + 100;
            MaximumSize = new Size(Width, Height);
            MaximizeBox = false;

            m_rectangles = new GridBox[width][];
            for (int widthTrav = 0; widthTrav < width; widthTrav++)
            {
                m_rectangles[widthTrav] = new GridBox[height];
                for (int heightTrav = 0; heightTrav < height; heightTrav++)
                {
                    if (widthTrav == 10 && heightTrav == 10)
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 10, heightTrav * 10 + 50, BoxType.Start);
                    }
                    else if (widthTrav == 100 && heightTrav == 50)
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 10, heightTrav * 10 + 50, BoxType.End);
                    }
                    else
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 10, heightTrav * 10 + 50, BoxType.Normal);
                    }
                }
            }


            m_resultLine = new List <GridLine>();

            searchGrid = new StaticGrid(width, height);

            jumpParam = new AStarParam(searchGrid, 50, HeuristicMode.EUCLIDEAN);
        }
コード例 #4
0
 internal override void _reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null)
 {
 }
コード例 #5
0
 public AStarParam(BaseGrid iGrid, float iweight, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
     : base(iGrid, iMode)
 {
     Weight = iweight;
 }
コード例 #6
0
 internal override void _reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null)
 {
     openList = new IntervalHeap <Node>();
     //openList.Clear();
 }
コード例 #7
0
        private void Redraw()
        {
            foreach (GridLine l in m_resultLine)
            {
                l.Dispose();
            }
            m_resultLine = new List <GridLine>();
            List <GridPos> resultList = new List <GridPos>();

            searchGrid = new StaticGrid(width, height);
            jumpParam  = new AStarParam(searchGrid, 50, HeuristicMode.EUCLIDEAN);
            Invalidate();

            for (int resultTrav = 0; resultTrav < m_resultLine.Count; resultTrav++)
            {
                m_resultLine[resultTrav].Dispose();
            }
            m_resultLine.Clear();
            for (int resultTrav = 0; resultTrav < m_resultBox.Count; resultTrav++)
            {
                m_resultBox[resultTrav].Dispose();
            }
            m_resultBox.Clear();

            GridPos startPos = new GridPos();
            GridPos endPos   = new GridPos();

            for (int widthTrav = 0; widthTrav < width; widthTrav++)
            {
                for (int heightTrav = 0; heightTrav < height; heightTrav++)
                {
                    if (m_rectangles[widthTrav][heightTrav].boxType != BoxType.Wall)
                    {
                        searchGrid.SetWalkableAt(new GridPos(widthTrav, heightTrav), true);
                    }
                    else
                    {
                        searchGrid.SetWalkableAt(new GridPos(widthTrav, heightTrav), false);
                    }
                    if (m_rectangles[widthTrav][heightTrav].boxType == BoxType.Start)
                    {
                        startPos.x = widthTrav;
                        startPos.y = heightTrav;
                    }
                    if (m_rectangles[widthTrav][heightTrav].boxType == BoxType.End)
                    {
                        endPos.x = widthTrav;
                        endPos.y = heightTrav;
                    }
                }
            }
            System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch();
            s.Start();
            jumpParam.Reset(startPos, endPos);
            resultList = AStarFinder.FindPath(jumpParam, isMultiThreading, lb_istrue);
            double time = s.ElapsedMilliseconds;

            s.Reset();


            if (isMultiThreading)
            {
                lb_multi.Text = "Time elapsed with multithreading: " + time + " ms.";
            }
            else
            {
                lb_multi.Text = "Time elapsed without multithreading: " + time + " ms.";
            }

            for (int resultTrav = 0; resultTrav < resultList.Count - 1; resultTrav++)
            {
                m_resultLine.Add(new GridLine(m_rectangles[resultList[resultTrav].x][resultList[resultTrav].y], m_rectangles[resultList[resultTrav + 1].x][resultList[resultTrav + 1].y]));
            }
            for (int widthTrav = 0; widthTrav < jumpParam.SearchGrid.width; widthTrav++)
            {
                for (int heightTrav = 0; heightTrav < jumpParam.SearchGrid.height; heightTrav++)
                {
                    if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav) == null)
                    {
                        continue;
                    }
                    if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav).isOpened)
                    {
                        ResultBox resultBox = new ResultBox(widthTrav * 10, heightTrav * 10 + 50, ResultBoxType.Opened);
                        m_resultBox.Add(resultBox);
                    }
                    if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav).isClosed)
                    {
                        ResultBox resultBox = new ResultBox(widthTrav * 10, heightTrav * 10 + 50, ResultBoxType.Closed);
                        m_resultBox.Add(resultBox);
                    }
                }
            }
            Invalidate();
        }
コード例 #8
0
 public BaseGrid(BaseGrid b)
 {
     m_gridRect = new GridRect(b.m_gridRect);
     width      = b.width;
     height     = b.height;
 }