Exemplo n.º 1
0
        bool Ready(int x0, int y0, int x1, int y1)
        {
            if (!InvalidIndex(x0, y0) || !InvalidIndex(x1, y1))
            {
                return(false);
            }
            if (IsBlock(x0, y0) || IsBlock(x1, y1))
            {
                return(false);
            }

            for (int i = 0; i < width_; ++i)
            {
                for (int j = 0; j < height_; ++j)
                {
                    var node = mapdata_[j, i];
                    node.Clear();
                }
            }

            openlist_.Clear();
            closelist_.Clear();

            start_ = GetNode(x0, y0);
            goal_  = GetNode(x1, y1);

            start_.h = GetH(start_);
            start_.SetCost();
            start_.viststate = VistState.Opened;
            openlist_.Add(start_);

            return(true);
        }
Exemplo n.º 2
0
        bool ProcessNeigbhors(Node current)
        {
            int parentx = current.x;
            int parenty = current.y;

            Point[] neigbhors = enableSlant ? sSlantNeigbhors : sNormalNeigbhors;

            for (int i = 0; i < neigbhors.Length; ++i)
            {
                int x = parentx + neigbhors[i].x;
                int y = parenty + neigbhors[i].y;
                if (!InvalidIndex(x, y))
                {
                    continue;
                }
                Node node = GetNode(x, y);
                if (node.closed)
                {
                    continue;
                }
                if (node.opened)
                {
                    continue;
                }
                if (node.blocked)
                {
                    node.viststate = VistState.Close;
                    closelist_.Add(node);
                    continue;
                }

                node.parent = current;
                node.g      = current.g + neigbhors[i].g;
                node.h      = GetH(node);
                node.SetCost();
                node.viststate = VistState.Opened;
                openlist_.Add(node);

                //if (node.Equals(goal_)) {
                //    return false;
                //}
            }
            return(true);
        }