예제 #1
0
        public int SearchCheck(int lastPathSelect)
        {
            int PathOut = -1;

            WayLenght = false;
            if (!TurnBack)
            {
                lastPath = (PathType)PathOut;
                if ((lastPathSelect & 2) != 0)
                {
                    lastNode[LastDir.Left] = new PathNode(nodescount++);
                    PathOut = (int)PathType.Left;
                }
                if ((lastPathSelect & 1) != 0)
                {
                    lastNode[LastDir.Forward] = new PathNode(nodescount++);
                    PathOut = (int)PathType.Forward;
                }
                if ((lastPathSelect & 4) != 0)
                {
                    lastNode[LastDir.Right] = new PathNode(nodescount++);
                    PathOut = (int)PathType.Right;
                }
                if (PathOut < 0)
                {
                    TargetNode = lastNode;
                    lastNode   = searchStack.Pop();
                    PathOut    = (int)PathType.Back;
                    LastDir.Rotate(PathType.Back);
                    TurnBack = true;
                }
                else
                {
                    WayLenght = true;
                    searchStack.Push(lastNode);
                    lastPath = LastDir[(PathType)PathOut];
                    LastDir.Rotate((PathType)PathOut);
                    lastNode[lastPath][LastDir.Back] = lastNode;
                    TargetNode = lastNode;
                    lastNode   = lastNode[lastPath];
                }
            }
            else
            {
                PathOut = -1;
                if ((lastPathSelect & 2) != 0)
                {
                    if (lastNode[LastDir.Left] != null)
                    {
                        if (lastNode[LastDir.Left].isNew)
                        {
                            PathOut = (int)PathType.Left;
                        }
                    }
                }
                if ((lastPathSelect & 1) != 0)
                {
                    if (lastNode[LastDir.Forward] != null)
                    {
                        if (lastNode[LastDir.Forward].isNew)
                        {
                            PathOut = (int)PathType.Forward;
                        }
                    }
                }
                if ((lastPathSelect & 4) != 0)
                {
                    if (lastNode[LastDir.Right] != null)
                    {
                        if (lastNode[LastDir.Right].isNew)
                        {
                            PathOut = (int)PathType.Right;
                        }
                    }
                }
                if (PathOut < 0)
                {
                    if (searchStack.Count > 1)
                    {
                        TargetNode = lastNode;
                        lastPath   = lastNode[searchStack.Pop()];
                        PathOut    = (int)LastDir.getDir(lastPath);
                        lastNode   = lastNode[lastPath];
                        LastDir.Rotate((PathType)PathOut);
                    }
                    else
                    {
                        if (!isOver)
                        {
                            isOver = true;
                        }
                        else
                        {
                            UpdateEndPoint();
                            lastlenght = 0;
                            TargetNode = nodes[PathType.Forward];
                            return(-1);
                        }
                        if (lastNode[PathType.Back].isDead)
                        {
                            searchStack.Push(lastNode);
                            PathOut = (int)LastDir.getDir(lastNode[lastNode[PathType.Back]]);
                            LastDir.Rotate((PathType)PathOut);
                            TargetNode = lastNode;
                            lastNode   = lastNode[PathType.Back];
                            TurnBack   = false;
                        }
                    }
                }
                else
                {
                    TargetNode = lastNode;
                    searchStack.Push(lastNode);
                    lastPath = LastDir[(PathType)PathOut];
                    LastDir.Rotate((PathType)PathOut);
                    lastNode[lastPath][LastDir.Back] = lastNode;
                    lastNode  = lastNode[lastPath];
                    TurnBack  = false;
                    WayLenght = true;
                }
            }
            return(PathOut);
        }
예제 #2
0
        //public List<PathNode> getAllNode(List<PathNode> list = null)
        //{
        //    List<PathNode> nodes = list;
        //    if (nodes == null)
        //    {
        //        nodes = new List<PathNode>();
        //    }
        //    for (int i = 0; i < paths.Length; i++)
        //    {
        //        if (this.paths[i] != null)
        //        {
        //            if (nodes.Contains(this.paths[i])) continue;
        //            nodes.Add(this.paths[i]);
        //            this.paths[i].getAllNode(nodes);
        //        }
        //    }
        //    return nodes;
        //}
        List <PathNode> DrawPathList(int x, int y, PathNode node, List <PathNode> pathlist = null, List <Point> ps = null)
        {
            List <PathNode> nodes  = pathlist;
            List <Point>    Points = ps;
            bool            f      = false;

            if (nodes == null)
            {
                f      = true;
                Points = new List <Point>();
                nodes  = new List <PathNode>();
            }
            int ax = 0, ay = 0;
            int w;

            for (int i = 0; i < node.paths.Length; i++)
            {
                if (node.paths[i] != null)
                {
                    if (nodes.Contains(node.paths[i]))
                    {
                        continue;
                    }
                    if ((w = node.pathlenght[i]) == 0)
                    {
                        w = width;
                    }
                    switch ((PathType)i)
                    {
                    case PathType.Forward:
                        ax = 0;
                        ay = -w;
                        break;

                    case PathType.Left:
                        ax = -w;
                        ay = 0;
                        break;

                    case PathType.Right:
                        ax = w;
                        ay = 0;
                        break;

                    case PathType.Back:
                        ax = 0;
                        ay = w;
                        break;
                    }
                    node.paths[i].x = x + ax;
                    node.paths[i].y = y + ay;
                    if (!node.paths[i].isDead)
                    {
                        Draw.DrawLine(norpen, x, y, x + ax, y + ay);
                        Draw.FillEllipse(norBrush, new Rectangle(x + ax - 2, y + ay - 2, 4, 4));
                        //if (lastNode == node.paths[i])
                        //    Draw.DrawEllipse(targetpen, new Rectangle(x + ax - 5, y + ay - 5, 10, 10));
                    }
                    else if (node.paths[i].isNew)
                    {
                        Draw.DrawLine(newpen, x, y, x + ax, y + ay);
                        //node.paths[i].x = x + ax;
                        //node.paths[i].y = y + ay;
                    }
                    else
                    {
                        Draw.DrawLine(norpen, x, y, x + ax, y + ay);
                        //Draw.DrawEllipse(deadpen, new Rectangle(x + ax - 5, y + ay - 5, 10, 10));
                        //if (lastNode == node.paths[i])
                        //    Draw.DrawEllipse(targetpen, new Rectangle(x + ax - 5, y + ay - 5, 10, 10));
                        Draw.DrawString(node.paths[i].pathName, strFont, Brushes.Black, x + ax + 5, y + ay + 5);
                        //node.paths[i].x = x + ax;
                        //node.paths[i].y = y + ay;
                        Points.Add(new Point(node.paths[i].x, node.paths[i].y));
                    }
                    nodes.Add(node.paths[i]);
                    DrawPathList(x + ax, y + ay, node.paths[i], nodes, Points);
                }
            }
            if (f)
            {
                foreach (Point p in Points)
                {
                    Draw.FillRectangle(deadBrush, p.X - 8, p.Y - 8, 16, 16);
                }
                Draw.FillEllipse(targetBrush, new Rectangle(lastNode.x - 5, lastNode.y - 5, 10, 10));
            }
            return(nodes);
        }