Exemplo n.º 1
0
        static bool Checkff(byte[][] buffer, SearchTree tree, PointInt max)
        {
            if (!Mark)
            {
                return(false);
            }

            int c  = 0;
            var em = tree.Yiled(0);

            while (em.MoveNext())
            {
                var cur = em.Current;
                var loc = cur.Curent;
                if (!loc.Vaild(max))
                {
                    continue;
                }
                if (buffer[loc.X][loc.Y] == 4)
                {
                    c++;
                    if (c >= 2)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        private static bool CalcPath(byte[][] buffer, PointInt loc, PointInt des, PointInt max, Action <byte[][]> callback, int wait)
        {
            var        root = new SearchTree(loc, 0);
            SearchTree opt  = root;
            var        next = opt;

            while (true)
            {
                if (next == null)
                {
                    return(false);
                }
                loc = next.Curent;

                if (!loc.Vaild(max))
                {
                    //遇到墙壁,处理区域点忽略

                    next = next.Parent;
                    goto endLab;
                }

                int i      = des.X - loc.X;
                int j      = des.Y - loc.Y;
                int status = i >= j ? 1 : 2;
                if (i == j && j == 0)
                {
                    buffer[loc.X][loc.Y] = 4;
                    DoCallback(callback, buffer, wait);
                    //到达终点寻址完毕
                    return(true);
                }
                if (buffer[loc.X][loc.Y] != 0)
                {
                    //寻址失败上层回溯
                    next = next.Parent;
                    goto endLab;
                }
                else
                {
                    //检查当前点的四个方向是否有通路
                    if (Checkff(buffer, next, max))
                    {
                        buffer[loc.X][loc.Y] = 4;
                        DoCallback(callback, buffer, wait);

                        buffer[loc.X][loc.Y] = 0;
                        DoCallback(callback, buffer, wait);

                        next = next.Parent;
                        //如果有则表示出现闭塞回路
                        goto endLab;
                    }
                    buffer[loc.X][loc.Y] = 4;
                    DoCallback(callback, buffer, wait);
                    next = next.YiledNext(status);
                    continue;
                }

endLab:
                if (next == null)
                {
                    return(false);
                }
                loc = next.Curent;

                i      = des.X - loc.X;
                j      = des.Y - loc.Y;
                status = i >= j ? 1 : 2;

doYiledNext:
                var n = next.YiledNext(status);
                if (n == null)
                {
                    buffer[loc.X][loc.Y] = 2;
                    DoCallback(callback, buffer, wait);
                    next = next.Parent;
                    goto endLab;
                }



                next = n;
                continue;
            }
        }