Пример #1
0
    //判断是否超过行动力
    public bool DisplayMoveRange(int[,] map, int startX, int startY, int endX, int endY, int mobility)
    {
        int       MoveLength = 0;
        AstarMove maze       = new AstarMove(map);
        Point     start      = new Point(startX, startY);
        Point     end        = new Point(endX, endY);
        var       parent     = maze.FindPath(start, end);

        if ((parent.X == -1) && (parent.Y == -1))
        {
            return(false);
        }
        while (parent != null)
        {
            MoveLength += 1;
            parent      = parent.ParentPoint;
        }

        if (MoveLength <= mobility + 1)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #2
0
    static void a()
    {
        int[,] array =
        {
            { 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 }
        };
        AstarMove maze   = new AstarMove(array);
        Point     start  = new Point(7, 14);
        Point     end    = new Point(5, 14);
        var       parent = maze.FindPath(start, end);

        Debug.Log("Print path:");

        while (parent != null)
        {
            Debug.Log(parent.X + ", " + parent.Y);
            parent = parent.ParentPoint;
        }
    }
Пример #3
0
    //最短路径的记录
    public void AiPath(int[,] map, int startX, int startY, int endX, int endY)
    {
        AstarMove maze   = new AstarMove(map);
        Point     start  = new Point(startX, startY);
        Point     end    = new Point(endX, endY);
        var       parent = maze.FindPath(start, end);

        while (parent != null)
        {
            AiMovePath.Push(parent);
            parent = parent.ParentPoint;
        }
    }