Exemple #1
0
    /// <summary>
    /// 将一个矩形分割成N个矩形
    /// </summary>
    public static List <Rectangle> Split(CheckIsBlock isBlock, int left, int top, int right, int bottom)
    {
        int[,] testMap = new int[right + 1, bottom + 1];
        List <Rectangle> rects = new List <Rectangle>();

        for (int y = top; y <= bottom; y++)
        {
            for (int x = left; x <= right; x++)
            {
                // Debug.Log("test x=" + x + " y=" + y + "  " + isBlock(x, y));

                if (testMap[x, y] == 0 && !isBlock(x, y))
                {
                    int       r    = FindRight(isBlock, testMap, x, y, right);
                    int       b    = FindBottom(isBlock, testMap, x, y, r, bottom);
                    Rectangle rect = new Rectangle(x, y, r - x + 1, b - y + 1);
                    FilLTestMap(testMap, rect);
                    rects.Add(rect);

                    x = r;
                }
            }
        }
        return(rects);
    }
Exemple #2
0
 public AStar(CheckIsBlock checkBlockHandle)
 {
     this.m_CheckBlockHandle = checkBlockHandle;
     m_NodePool  = new NodePool();
     m_OpenQueue = new PriorityQueue <Node>(50, new NodeComparer());
     m_CloseDic  = new Dictionary <int, Node>();
 }
Exemple #3
0
    /// <summary>
    /// 找到最优
    /// </summary>
    /// <param name="isBlock"></param>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="right"></param>
    /// <returns></returns>
    private static int FindRight(CheckIsBlock isBlock, int[,] testMap, int left, int top, int right)
    {
        int x = left;

        for (int y = top; x < right; x++)
        {
            if (testMap[x + 1, y] == 1 || isBlock(x + 1, y))
            {
                break;
            }
        }
        return(x);
    }
Exemple #4
0
    private static int FindBottom(CheckIsBlock isBlock, int[,] testMap, int left, int top, int right, int bottom)
    {
        int y;

        for (y = top; y < bottom; y++)
        {
            for (int x = left; x <= right; x++)
            {
                if (testMap[x, y + 1] == 1 || isBlock(x, y + 1))
                {
                    return(y);
                }
            }
        }
        return(y);
    }
Exemple #5
0
    public delegate bool CheckIsBlock(int x, int y);//检测x,y是否是阻碍

    public static List <Rectangle> Split(CheckIsBlock isBlock, Rectangle rect)
    {
        return(Split(isBlock, rect.x, rect.y, rect.right, rect.bottom));
    }