Esempio n. 1
0
        public bool setTargetPoint(PathNode node)
        {
            TargetDirList.Clear();
            if (lastNode == null)
            {
                return(false);
            }
            if (node.isNew || !node.isDead)
            {
                return(false);
            }
            if (lastNode == node)
            {
                return(false);
            }
            TargetPath = lastNode.gotoNode(node);
            if (TargetPath == null)
            {
                return(false);
            }
            PathDir  dir = LastPathDir;
            PathNode nt  = null;

            foreach (PathNode n in TargetPath)
            {
                PathType type;
                if (nt == null)
                {
                    nt = n;
                    continue;
                }
                type = dir.getDir(nt[n]);
                dir.Rotate(type);
                TargetDirList.Add(type);
                nt = n;
            }
            return(true);
        }
Esempio n. 2
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);
        }