Exemplo n.º 1
0
 public int CompareTo(AStarFindPath.OpenItem other)
 {
     if (this.f < other.f)
     {
         return(-1);
     }
     else
     {
         return(1);
     }
 }
Exemplo n.º 2
0
        private bool RealFindWay(Point start_point, Point end_point)
        {
            Point cur_point = new Point(start_point);

            while (true)
            {
                //当前点设为闭点
                this.m_map[cur_point.x][cur_point.y].close = true;
                this.m_map[cur_point.x][cur_point.y].x     = cur_point.x;
                this.m_map[cur_point.x][cur_point.y].y     = cur_point.y;

                //设置搜索范围
                #region
                int x_begin = cur_point.x - 1;
                if (x_begin < 0)
                {
                    x_begin = 0;
                }

                int x_end = cur_point.x + 1;
                if (x_end >= this.m_mask_width)
                {
                    x_end = this.m_mask_width - 1;
                }

                int y_begin = cur_point.y - 1;
                if (y_begin < 0)
                {
                    y_begin = 0;
                }
                int y_end = cur_point.y + 1;
                if (y_end >= this.m_mask_height)
                {
                    y_end = this.m_mask_height - 1;
                }
                #endregion

                //遍历四周8个点
                for (int i = x_begin; i <= x_end; i++)
                {
                    for (int j = y_begin; j <= y_end; j++)
                    {
                        if (!this.m_map[i][j].close && !this.NoWalk(i, j))
                        {
                            if (i == end_point.x && j == end_point.y)
                            {
                                bool slash_blocked = false;//斜角是否不可达
                                //斜角处理
                                if (i != cur_point.x && j != cur_point.y && (this.NoWalk(i, cur_point.y) || this.NoWalk(cur_point.x, j)))
                                {
                                    slash_blocked = true;
                                }
                                if (!slash_blocked)
                                {
                                    this.m_map[i][j].parant = this.m_map[cur_point.x][cur_point.y];
                                    this.m_map[i][j].x      = i;
                                    this.m_map[i][j].y      = j;
                                    return(true);
                                }
                            }
                            else
                            {
                                int  h        = i - cur_point.x;
                                int  c        = j - cur_point.y;
                                int  next_dir = this.POINT_DIR[h + 1, c + 1];
                                bool is_slash = h * c != 0;
                                this.CalcWeight(cur_point.x, cur_point.y, i, j, is_slash, next_dir);
                            }
                        }
                    }
                }

                //在开集合中寻找最小F的有效点
                bool cant_find = true;
                AStarFindPath.OpenItem next_open = new AStarFindPath.OpenItem();
                while (this.m_open_list.Front(ref next_open))
                {
                    this.m_open_list.PopFront();
                    if (!this.m_map[next_open.x][next_open.y].close)
                    {
                        cur_point.x = next_open.x;
                        cur_point.y = next_open.y;
                        cant_find   = false;
                        break;
                    }
                }
                if (cant_find)
                {
                    this.m_end_point = cur_point;
                    return(false);
                }
            }
        }