コード例 #1
0
    private IEnumerator OpenPath(int depth)
    {
        goals.UpdateGoals();
        currentList = new List <Node>();
        Node bestNode = null;

        int countDepth = 0;

        //check around the player
        countDepth = depth;
        int pLine    = playerPosition.line;
        int pCollumn = playerPosition.collumn;

        //Debug.LogWarning(playerPosition.line + " | " + playerPosition.collumn);

        for (int i = 0; i < depth; i++)
        {
            //check left
            Node left  = CheckArray(pLine, pCollumn - countDepth);
            Node right = CheckArray(pLine, pCollumn + countDepth);
            Node up    = CheckArray(pLine - countDepth, pCollumn);
            Node down  = CheckArray(pLine + countDepth, pCollumn);

            //diagonals
            Node leftUp    = CheckArray(pLine - countDepth, pCollumn - countDepth);
            Node leftDown  = CheckArray(pLine + countDepth, pCollumn - countDepth);
            Node rightUp   = CheckArray(pLine - countDepth, pCollumn + countDepth);
            Node rightDown = CheckArray(pLine + countDepth, pCollumn + countDepth);

            CheckNode(left);
            CheckNode(right);
            CheckNode(up);
            CheckNode(down);

            CheckNode(leftUp);
            CheckNode(leftDown);
            CheckNode(rightUp);
            CheckNode(rightDown);

            countDepth++;
        }

        bestNode = currentList.OrderByDescending(x => x.score).Last();

        services.NotifyOpenPath(currentList);

        yield return(new WaitForSeconds(timeAI));

        StartCoroutine(ExecuteMovement(bestNode));

        //calc de score aroud the player
    }