コード例 #1
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();
        }
コード例 #2
0
 public abstract bool IsWalkableAt(GridPos iPos);
コード例 #3
0
 public abstract bool SetWalkableAt(GridPos iPos, bool iWalkable);
コード例 #4
0
 public abstract Node GetNodeAt(GridPos iPos);